SeliseBlocks.LMT.Client 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package SeliseBlocks.LMT.Client --version 1.0.2
                    
NuGet\Install-Package SeliseBlocks.LMT.Client -Version 1.0.2
                    
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="SeliseBlocks.LMT.Client" Version="1.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SeliseBlocks.LMT.Client" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="SeliseBlocks.LMT.Client" />
                    
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 SeliseBlocks.LMT.Client --version 1.0.2
                    
#r "nuget: SeliseBlocks.LMT.Client, 1.0.2"
                    
#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 SeliseBlocks.LMT.Client@1.0.2
                    
#: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=SeliseBlocks.LMT.Client&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=SeliseBlocks.LMT.Client&version=1.0.2
                    
Install as a Cake Tool

Blocks.LMT.Client

A robust and high-performance .NET client library for logging and distributed tracing with Azure Service Bus integration. Designed for enterprise applications requiring centralized log and trace management with built-in resilience, batching, and automatic retry mechanisms.

โœจ Features

  • ๐Ÿš€ High Performance - Automatic batching reduces network overhead and improves throughput
  • ๐Ÿ”„ Automatic Retry Logic - Exponential backoff with configurable retry attempts
  • ๐Ÿ’พ Failed Batch Queue - Prevents data loss during transient failures
  • ๐Ÿงต Thread-Safe - Built with concurrent collections for multi-threaded environments
  • ๐Ÿ“Š OpenTelemetry Integration - Industry-standard distributed tracing support
  • ๐Ÿข Multi-Tenant Support - Automatic tenant isolation via baggage propagation
  • โšก Zero Dependencies on Logging Frameworks - Works independently or alongside Serilog, NLog, etc.
  • ๐ŸŽฏ Azure Service Bus Native - Optimized for Azure Service Bus Topics and Subscriptions
  • ๐Ÿ”Œ Easy Integration - Simple dependency injection setup with minimal configuration

๐Ÿ—๏ธ Architecture

โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
โ”‚                      Your Application                          โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”              โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”        โ”‚
โ”‚  โ”‚  ILmtLogger  โ”‚              โ”‚  OpenTelemetry       โ”‚        โ”‚
โ”‚  โ”‚   (Logs)     โ”‚              โ”‚  (Traces)            โ”‚        โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜              โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜        โ”‚
โ”‚         โ”‚                                  โ”‚                   โ”‚
โ”‚         โ”‚  Batching & Retry                โ”‚  Batching & Retry โ”‚
โ”‚         โ–ผ                                  โ–ผ                   โ”‚
โ”‚  โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”      โ”‚
โ”‚  โ”‚              Azure Service Bus                       โ”‚      โ”‚
โ”‚  โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜      โ”‚
โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ผโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚  LMT Service Worker   โ”‚
          โ”‚  (Subscriptions)      โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”ฌโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜
                      โ”‚
                      โ–ผ
          โ”Œโ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”
          โ”‚   MongoDB Storage     โ”‚
          โ”‚  โ€ข Logs by Service    โ”‚
          โ”‚  โ€ข Traces by Tenant   โ”‚
          โ””โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”€โ”˜

๐Ÿ“ฆ Installation

Install via NuGet Package Manager:

dotnet add package Blocks.LMT.Client

Or via Package Manager Console:

Install-Package Blocks.LMT.Client

๐Ÿš€ Quick Start

1. Add to your appsettings.json:

{
  "Lmt": {
    "ServiceName": "MyMicroservice",
    "ServiceBusConnectionString": "Endpoint=sb://your-namespace.servicebus.windows.net/;SharedAccessKeyName=RootManageSharedAccessKey;SharedAccessKey=your-key",
    "LogBatchSize": 100,
    "TraceBatchSize": 1000,
    "FlushIntervalSeconds": 5,
    "MaxRetries": 3,
    "MaxFailedBatches": 100,
    "EnableLogging": true,
    "EnableTracing": true
  }
}

2. Register services in Program.cs or Startup.cs:

using Blocks.LMT.Client;

// Add LMT Client
builder.Services.AddLmtClient(builder.Configuration);

// Add OpenTelemetry for distributed tracing
builder.Services.AddOpenTelemetry()
    .WithTracing(tracerBuilder =>
    {
        tracerBuilder
            .AddSource("MyMicroservice") // Match your ServiceName
            .AddAspNetCoreInstrumentation()
            .AddHttpClientInstrumentation()
            .AddLmtTracing(builder.Services.BuildServiceProvider()
                .GetRequiredService<LmtOptions>());
    });

3. Use in your code:

public class OrderService
{
    private readonly ILmtLogger _logger;
    private readonly ActivitySource _activitySource;

    public OrderService(ILmtLogger logger)
    {
        _logger = logger;
        _activitySource = new ActivitySource("MyMicroservice");
    }

    public async Task<Order> CreateOrder(CreateOrderRequest request)
    {
        using var activity = _activitySource.StartActivity("CreateOrder");
        
        _logger.LogInformation("Creating order", new Dictionary<string, object>
        {
            { "CustomerId", request.CustomerId },
            { "OrderTotal", request.Total }
        });

        try
        {
            // Your business logic
            var order = await ProcessOrder(request);
            
            _logger.LogInformation("Order created successfully", new Dictionary<string, object>
            {
                { "OrderId", order.Id },
                { "CustomerId", request.CustomerId }
            });
            
            return order;
        }
        catch (Exception ex)
        {
            _logger.LogError("Failed to create order", ex, new Dictionary<string, object>
            {
                { "CustomerId", request.CustomerId },
                { "ErrorType", ex.GetType().Name }
            });
            throw;
        }
    }
}

โš™๏ธ Configuration

Configuration Options

Property Type Default Description
ServiceName string required Unique identifier for your service
ServiceBusConnectionString string required Azure Service Bus connection string
LogBatchSize int 100 Number of logs to batch before sending
TraceBatchSize int 1000 Number of traces to batch before sending
FlushIntervalSeconds int 5 Interval to flush batches automatically
MaxRetries int 3 Maximum retry attempts for failed sends
MaxFailedBatches int 100 Maximum failed batches to queue
EnableLogging bool true Enable/disable logging
EnableTracing bool true Enable/disable tracing

Configuration via Code

Instead of using appsettings.json, you can configure via code:

services.AddLmtClient(options =>
{
    options.ServiceName = "MyMicroservice";
    options.ServiceBusConnectionString = "Endpoint=sb://...";
    options.LogBatchSize = 100;
    options.TraceBatchSize = 1000;
    options.FlushIntervalSeconds = 5;
    options.EnableLogging = true;
    options.EnableTracing = true;
});

Environment Variables

You can also use environment variables (useful for containerized environments):

Lmt__ServiceName=MyMicroservice
Lmt__ServiceBusConnectionString=Endpoint=sb://...
Lmt__LogBatchSize=100
Lmt__EnableLogging=true

๐Ÿ“š Usage

Logging

Basic Logging
public class UserService
{
    private readonly ILmtLogger _logger;

    public UserService(ILmtLogger logger)
    {
        _logger = logger;
    }

    public async Task RegisterUser(User user)
    {
        _logger.LogInformation($"Registering user: {user.Email}");
        
        // Your logic
        
        _logger.LogInformation("User registered successfully", new Dictionary<string, object>
        {
            { "UserId", user.Id },
            { "Email", user.Email }
        });
    }
}
Log Levels
// Trace - Most detailed information
_logger.LogTrace("Entering method ProcessPayment");

// Debug - Debugging information
_logger.LogDebug("Payment gateway response received");

// Information - General flow
_logger.LogInformation("Payment processed successfully");

// Warning - Unexpected but handled situations
_logger.LogWarning("Payment took longer than expected");

// Error - Errors and exceptions
_logger.LogError("Payment failed", exception);

// Critical - Critical failures
_logger.LogCritical("Payment gateway is down", exception);
Structured Logging
_logger.LogInformation("Order processed", new Dictionary<string, object>
{
    { "OrderId", orderId },
    { "CustomerId", customerId },
    { "Total", totalAmount },
    { "ItemCount", items.Count },
    { "ProcessingTime", processingTime.TotalMilliseconds }
});
Exception Logging
try
{
    await ProcessPayment(payment);
}
catch (PaymentException ex)
{
    _logger.LogError("Payment processing failed", ex, new Dictionary<string, object>
    {
        { "PaymentId", payment.Id },
        { "Amount", payment.Amount },
        { "Currency", payment.Currency },
        { "Gateway", payment.Gateway }
    });
    throw;
}

๐ŸŽฏ Advanced Scenarios

Custom Batch Sizes for High-Throughput Services

services.AddLmtClient(options =>
{
    options.ServiceName = "HighThroughputService";
    options.ServiceBusConnectionString = "...";
    options.LogBatchSize = 500;      // Larger batches
    options.TraceBatchSize = 5000;    // Much larger for traces
    options.FlushIntervalSeconds = 2; // More frequent flushes
});

Conditional Logging/Tracing

services.AddLmtClient(options =>
{
    options.ServiceName = "MyService";
    options.ServiceBusConnectionString = "...";
    
    // Disable in development, enable in production
    var environment = builder.Environment;
    options.EnableLogging = !environment.IsDevelopment();
    options.EnableTracing = !environment.IsDevelopment();
});

Integration with Existing Logging Frameworks

You can use LMT alongside Serilog, NLog, or Microsoft.Extensions.Logging:

public class PaymentService
{
    private readonly ILogger<PaymentService> _msLogger;  // Microsoft logger
    private readonly ILmtLogger _lmtLogger;              // LMT logger

    public PaymentService(
        ILogger<PaymentService> msLogger, 
        ILmtLogger lmtLogger)
    {
        _msLogger = msLogger;
        _lmtLogger = lmtLogger;
    }

    public async Task ProcessPayment(Payment payment)
    {
        // Log to console/file via MS Logger
        _msLogger.LogInformation("Processing payment {PaymentId}", payment.Id);
        
        // Send to centralized LMT system
        _lmtLogger.LogInformation("Processing payment", new Dictionary<string, object>
        {
            { "PaymentId", payment.Id },
            { "Amount", payment.Amount }
        });
        
        // Your logic
    }
}

Sampling for High-Volume Traces

builder.Services.AddOpenTelemetry()
    .WithTracing(tracerBuilder =>
    {
        tracerBuilder
            .AddSource("MyMicroservice")
            // Sample only 10% of traces to reduce volume
            .SetSampler(new TraceIdRatioBasedSampler(0.1))
            .AddLmtTracing(builder.Services.BuildServiceProvider()
                .GetRequiredService<LmtOptions>());
    });

๐Ÿ“– API Reference

ILmtLogger Interface

public interface ILmtLogger
{
    void Log(LmtLogLevel level, string message, Exception exception = null, 
             Dictionary<string, object> properties = null);
    void LogTrace(string message, Dictionary<string, object> properties = null);
    void LogDebug(string message, Dictionary<string, object> properties = null);
    void LogInformation(string message, Dictionary<string, object> properties = null);
    void LogWarning(string message, Dictionary<string, object> properties = null);
    void LogError(string message, Exception exception = null, 
                  Dictionary<string, object> properties = null);
    void LogCritical(string message, Exception exception = null, 
                     Dictionary<string, object> properties = null);
}

LmtLogLevel Enum

public enum LmtLogLevel
{
    Trace = 0,      // Most detailed
    Debug = 1,      // Debug information
    Information = 2, // General flow
    Warning = 3,    // Unexpected situations
    Error = 4,      // Errors and exceptions
    Critical = 5    // Critical failures
}

Extension Methods

// Register LMT Client
IServiceCollection.AddLmtClient(IConfiguration configuration)
IServiceCollection.AddLmtClient(Action<LmtOptions> configureOptions)

// Add LMT tracing to OpenTelemetry
TracerProviderBuilder.AddLmtTracing(LmtOptions options)

๐Ÿ“„ License

This project is licensed under the MIT License - see the LICENSE file for details.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  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 (1)

Showing the top 1 NuGet packages that depend on SeliseBlocks.LMT.Client:

Package Downloads
SeliseBlocks.Genesis

Blocks Genesis

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
9.0.3 2,920 10/27/2025
9.0.2 241 10/23/2025
9.0.1 255 10/15/2025
1.0.10 185 10/15/2025
1.0.9 181 10/15/2025
1.0.8 208 10/15/2025
1.0.7 192 10/14/2025
1.0.6 191 10/14/2025
1.0.5 192 10/14/2025
1.0.3 201 10/11/2025
1.0.2 160 10/11/2025
1.0.1 108 10/11/2025
1.0.0 208 10/9/2025