Home

Awesome

<p align="center"> <img src="servicebuslogging.jpg" alt="Service bus Logging Plugin" width="100"/> </p>

ServiceBus.LoggingPlugin

Plugin to log Service bus messages

This is an add-in for Microsoft.Azure.ServiceBus client

Allow to log messages before being sent by tracing or saving in an Azure Storage Account Table.

Build status CodeFactor NuGet NuGet License: MIT

Nuget package

To Install from the Nuget Package Manager Console

PM > Install-Package ServiceBus.LoggingPlugin 
NET CLI - dotnet add package ServiceBus.LoggingPlugin
paket paket add ServiceBus.LoggingPlugin

Available here https://www.nuget.org/packages/ServiceBus.LoggingPlugin

Examples

Use Tracing method

Configuration and registration

      queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

      queueClient.RegisteredPlugins.Add(new LoggingPlugin(configurations =>
      {
          configurations.LoggingType = LoggingType.Trace;
      }));

Using Storage Account Mode

Configuration and registration

      queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

      queueClient.RegisteredPlugins.Add(new LoggingPlugin(configurations =>
      {
          configurations.LoggingType = LoggingType.StorageTable;
          configurations.SendInBackground = true;
          configurations.ConfigureStorageAccount(information =>
              {
                  information.ConnectionString = "Insert Storage Connection string";
              });
      }));

Optional Configurations Custom Partition key Custom storage table name

 configurations.ConfigureStorageAccount(information =>
                {
                    information.ConnectionString = "Insert Storage Connection string";
                    information.PartitionKey = "YourPartitionKey";
                    information.TableName = "YourTableName";
                });

Simple Log Method

Configuration and registration

      queueClient = new QueueClient(ServiceBusConnectionString, QueueName);

      queueClient.RegisteredPlugins.Add(new LoggingPlugin(configurations =>
      {
          configurations.LoggingType = LoggingType.None;
          configurations.Log = message =>
          {
              // you can handle manually the message here
              var m1 = message;
          };
      }));

Use Custom LoggerService

Configuration and registration

      public class CustomLoggingService : ILoggingService
      {
          public void Dispose()
          {
          }

          public bool Disposed { get; set; }

          public Task LogSentMessage(Message message)
          {
              // implement your logic here
          }

          public void SetConfigurations(ILogginConfigurations configurations)
          {
          }
      }
      
       queueClient = new QueueClient(ServiceBusConnectionString, QueueName);
       queueClient.RegisterLoggingService(new CustomLoggingService());

Icon

Created by Mariana Alemanno

Made with ❤ in DGENIX