ServiceBusWireTap.Middleware.Logging 1.0.0

dotnet add package ServiceBusWireTap.Middleware.Logging --version 1.0.0
                    
NuGet\Install-Package ServiceBusWireTap.Middleware.Logging -Version 1.0.0
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="ServiceBusWireTap.Middleware.Logging" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="ServiceBusWireTap.Middleware.Logging" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="ServiceBusWireTap.Middleware.Logging" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add ServiceBusWireTap.Middleware.Logging --version 1.0.0
                    
#r "nuget: ServiceBusWireTap.Middleware.Logging, 1.0.0"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package ServiceBusWireTap.Middleware.Logging@1.0.0
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=ServiceBusWireTap.Middleware.Logging&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=ServiceBusWireTap.Middleware.Logging&version=1.0.0
                    
Install as a Cake Tool

📦 Service Bus WireTap Middleware for .NET Isolated Azure Functions

A reusable middleware for Azure Functions (.NET 8+ Isolated Worker), enabling wire‑tap-style logging of complete ServiceBusReceivedMessage—capturing body, metadata, and application properties—regardless of typed function signatures.

Part of the WireTapMiddleware collection for messaging broker interception.

🔍 Key Features

  • Works seamlessly with typed bindings (e.g., POCOs), yet taps the full ServiceBusReceivedMessage for deep visibility
  • Built on IFunctionsWorkerMiddleware, intercepting messages in a central place, no per-function changes needed
  • Logs MessageId, CorrelationId, full body text, and all ApplicationProperties
  • Integrates with built-in logging (Application Insights/ILogger)
  • Configurable logging options for security and performance
  • Custom log actions for integration with external systems

🚀 Quick Start

1. Install the Package

dotnet add package ServiceBusWireTap.Middleware.Logging

2. Register the Middleware

In your Program.cs:

using Microsoft.Extensions.Hosting;
using ServiceBusWireTap.Middleware.Logging;

var host = new HostBuilder()
    .UseServiceBusWireTap() // Add this line
    .ConfigureFunctionsWorkerDefaults()
    .Build();

host.Run();

3. Your Functions Work Unchanged

[Function("ProcessOrder")]
public async Task ProcessOrder([ServiceBusTrigger("orders", Connection = "ServiceBus")] Order order)
{
    // Your business logic here - unchanged!
    // The middleware automatically logs the complete ServiceBusReceivedMessage
}

⚙️ Configuration Options

Basic Configuration

var host = new HostBuilder()
    .UseServiceBusWireTap(options =>
    {
        options.LogLevel = LogLevel.Information;
        options.IncludeMessageBody = true;
        options.MaxBodySizeToLog = 10 * 1024; // 10KB
    })
    .ConfigureFunctionsWorkerDefaults()
    .Build();

Advanced Configuration with Custom Actions

var host = new HostBuilder()
    .UseServiceBusWireTap(options =>
    {
        options.LogLevel = LogLevel.Debug;
        options.IncludeMessageBody = false; // Don't log body for security
        options.CustomLogAction = async (logEntry) =>
        {
            // Send to custom telemetry system
            await CustomTelemetryClient.SendAsync(logEntry);
        };
    })
    .ConfigureFunctionsWorkerDefaults()
    .Build();

🔧 Configuration Options Reference

Option Type Default Description
LogLevel LogLevel Information The log level for wire-tap entries
IncludeMessageBody bool true Whether to include message body in logs
MaxBodySizeToLog int? 10240 Maximum body size to log (bytes)
CustomLogAction Func<ServiceBusMessageLogEntry, Task>? null Custom action for log entries

🛡️ Security Considerations

For sensitive data, consider:

.UseServiceBusWireTap(options =>
{
    options.IncludeMessageBody = false; // Exclude body for sensitive data
    options.MaxBodySizeToLog = 1024;    // Limit body size
})

🔍 Example Function Types Supported

POCO Binding

[Function("ProcessOrder")]
public async Task ProcessOrder([ServiceBusTrigger("orders")] Order order)
{
    // Middleware logs the complete ServiceBusReceivedMessage
    // Your function gets the typed Order object
}

String Binding

[Function("ProcessMessage")]
public async Task ProcessMessage([ServiceBusTrigger("messages")] string message)
{
    // Middleware logs full message details
    // Your function gets the string body
}

ServiceBusReceivedMessage Binding

[Function("ProcessRawMessage")]
public async Task ProcessRawMessage([ServiceBusTrigger("raw")] ServiceBusReceivedMessage message)
{
    // Middleware logs the message
    // Your function gets the raw message object
}

🔄 Integration with Application Insights

The middleware integrates seamlessly with Application Insights:

// In your Function App configuration
builder.Services.AddApplicationInsightsTelemetryWorkerService();

// Wire-tap logs will appear in Application Insights with custom properties
// Query example:
// traces | where message contains "ServiceBus Message Intercepted"

🎯 Use Cases

  • Message Auditing: Track all ServiceBus messages for compliance
  • Debugging: Deep visibility into message flow without code changes
  • Monitoring: Real-time insights into message processing
  • Analytics: Custom telemetry integration for business intelligence

🔮 Future Brokers

This is part of the WireTapMiddleware collection. Future implementations will include:

  • RabbitMQ WireTap Middleware
  • Apache Kafka WireTap Middleware
  • Amazon SQS WireTap Middleware

📝 License

This project is licensed under the MIT License.

🤝 Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.0 95 7/12/2025