MasterZdran.Logging.Configuration 0.1.0

Prefix Reserved
dotnet add package MasterZdran.Logging.Configuration --version 0.1.0
                    
NuGet\Install-Package MasterZdran.Logging.Configuration -Version 0.1.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="MasterZdran.Logging.Configuration" Version="0.1.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MasterZdran.Logging.Configuration" Version="0.1.0" />
                    
Directory.Packages.props
<PackageReference Include="MasterZdran.Logging.Configuration" />
                    
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 MasterZdran.Logging.Configuration --version 0.1.0
                    
#r "nuget: MasterZdran.Logging.Configuration, 0.1.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 MasterZdran.Logging.Configuration@0.1.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=MasterZdran.Logging.Configuration&version=0.1.0
                    
Install as a Cake Addin
#tool nuget:?package=MasterZdran.Logging.Configuration&version=0.1.0
                    
Install as a Cake Tool

MasterZdran.Logging.AzureTableStorage

Production-ready Azure Table Storage logging for .NET with Microsoft.Extensions.Logging support

License: MIT .NET NuGet Tests

A professional, enterprise-grade logging library that writes structured logs to Azure Table Storage with full support for distributed tracing, async operations, and Microsoft's logging abstractions.


๐Ÿš€ Quick Start

Installation

From NuGet.org
# Core logging library
dotnet add package MasterZdran.Logging.AzureTableStorage

# Configuration providers (optional)
dotnet add package MasterZdran.Logging.Configuration
From Local Build
# Build packages
.\build-nuget.ps1

# Install from local directory
dotnet add package MasterZdran.Logging.AzureTableStorage --source ./nupkgs --version 0.1.0

Basic Usage

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MasterZdran.Logging.AzureTableStorage;

// Setup with Dependency Injection
var services = new ServiceCollection();
services.AddAzureTableStorageLogging(
    connectionString: "DefaultEndpointsProtocol=https;AccountName=...",
    tableName: "logs",
    loggerName: "MyApp"
);

var serviceProvider = services.BuildServiceProvider();

// Use standard ILogger<T> - works like any other logging provider!
var logger = serviceProvider.GetRequiredService<ILogger<MyService>>();
logger.LogInformation("Application started");

โœจ Key Features

  • โœ… Microsoft.Extensions.Logging - Full ILogger and ILogger<T> support
  • โœ… Async/Await - Non-blocking async operations throughout
  • โœ… Distributed Tracing - Built-in trace ID support for microservices
  • โœ… Structured Logging - Rich metadata and context tracking
  • โœ… Azure Integration - Key Vault, App Configuration, Managed Identity
  • โœ… Type Safe - Nullable reference types, compile-time safety
  • โœ… Security First - OWASP best practices, input validation, injection prevention
  • โœ… Well Tested - 113 unit & integration tests, 100% pass rate
  • โœ… Cross-Platform - .NET 10.0, .NET 9.0, .NET 8.0, and .NET 7.0

๐Ÿ“– Usage Examples

ASP.NET Core Application

// In Program.cs
builder.Services.AddAzureTableStorageLogging(
    connectionString: builder.Configuration["AzureTableStorage:ConnectionString"],
    tableName: "logs",
    loggerName: "MyWebApi"
);

// In your controllers/services - standard DI injection
public class OrderController : ControllerBase
{
    private readonly ILogger<OrderController> _logger;

    public OrderController(ILogger<OrderController> logger)
    {
        _logger = logger;
    }

    [HttpPost]
    public async Task<IActionResult> CreateOrder(Order order)
    {
        _logger.LogInformation("Creating order {OrderId}", order.Id);
        // Logs are automatically sent to Azure Table Storage
        return Ok();
    }
}

Console Application

using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using MasterZdran.Logging.AzureTableStorage;

var services = new ServiceCollection();
services.AddAzureTableStorageLogging(
    connectionString: "UseDevelopmentStorage=true", // Azurite for local dev
    tableName: "logs",
    loggerName: "ConsoleApp"
);

var serviceProvider = services.BuildServiceProvider();
var logger = serviceProvider.GetRequiredService<ILogger<Program>>();

logger.LogInformation("Application started");
logger.LogWarning("Low memory detected");
logger.LogError(exception, "Failed to process {ItemId}", itemId);

Advanced: Direct Async API

// For high-performance scenarios, use the direct async logger
var logger = serviceProvider.GetRequiredService<AzureTableStorageLogger>();

await logger.InformationAsync(
    "User action performed",
    traceId: Activity.Current?.Id,
    metadata: new Dictionary<string, object>
    {
        { "userId", "12345" },
        { "action", "purchase" },
        { "amount", 99.99 }
    }
);

// Query logs
var query = new LogQuery
{
    PageSize = 50,
    OrderBy = "Timestamp",
    Filters = new Dictionary<string, object> { { "LogLevel", "Error" } }
};

var (logs, continuationToken) = await logger.GetLogsAsync(query);

With Azure Key Vault

using MasterZdran.Logging.Configuration;

var config = new ConfigurationBuilder()
    .AddJsonFile("appsettings.json")
    .AddAzureKeyVault("https://myvault.vault.azure.net")
    .Build();

var loggingConfig = config.GetAzureTableStorageLoggingConfiguration();

services.AddAzureTableStorageLogging(
    loggingConfig.ConnectionString,
    loggingConfig.TableName,
    loggingConfig.LoggerName
);

๐Ÿ—๏ธ Architecture

Your Application
    โ†“
ILogger<T> / ILogger (Microsoft.Extensions.Logging)
    โ†“
AzureTableStorageLoggerProvider (implements ILoggerProvider)
    โ†“
AzureTableStorageLoggerWrapper (implements ILogger)
    โ†“
AzureTableStorageLogger (async logging core)
    โ†“
ILogStorage Interface
    โ†“
AzureTableStorage Implementation
    โ†“
Azure Table Storage

Key Components:

  • ILogger Integration: Seamless Microsoft.Extensions.Logging compatibility
  • Async Core: Non-blocking operations with proper async/await
  • Storage Abstraction: Testable via ILogStorage interface
  • Security Layer: Input validation, sanitization, injection prevention
  • Configuration: Multiple sources (Key Vault, App Configuration, JSON)

๐Ÿ“š Documentation

Detailed Documentation


๐Ÿ”ง Configuration

appsettings.json

{
  "AzureTableStorageLogging": {
    "ConnectionString": "DefaultEndpointsProtocol=https;AccountName=...",
    "TableName": "logs",
    "LoggerName": "MyApplication",
    "DefaultTraceId": "default-trace",
    "EnvironmentName": "Production"
  }
}

Azure Key Vault

Store sensitive configuration in Azure Key Vault:

  • AzureTableStorageLogging--ConnectionString
  • AzureTableStorageLogging--TableName

Environment Variables

export AzureTableStorageLogging__ConnectionString="..."
export AzureTableStorageLogging__TableName="logs"

๐Ÿ”’ Security Features

  • โœ… Input Validation - All inputs validated before processing
  • โœ… OData Injection Prevention - Automatic escaping of filter values
  • โœ… Sanitization - Control character removal, length limits
  • โœ… Secure Exceptions - No sensitive data in error messages
  • โœ… Azure Key Vault - Secrets management integration
  • โœ… Managed Identity - Azure AD authentication support
  • โœ… TLS/HTTPS - Encrypted communication enforced

Follows OWASP Top 10 security guidelines. See Security Best Practices for details.


๐Ÿงช Testing

The library is thoroughly tested with 114 passing tests covering:

  • Unit tests for all public APIs
  • Integration tests with Azure Table Storage
  • Security validation tests (injection prevention, sanitization)
  • Configuration provider tests
  • Exception handling tests
# Run tests
dotnet test

# With coverage (requires coverlet)
dotnet test --collect:"XPlat Code Coverage"

See Testing Guide for testing best practices.


๐Ÿ“ฆ What's Included

Core Library (MasterZdran.Logging.AzureTableStorage)

  • AzureTableStorageLogger - Main async logger
  • AzureTableStorageLoggerProvider - ILoggerProvider implementation
  • AzureTableStorageLoggerWrapper - ILogger adapter
  • ILogStorage - Storage abstraction
  • AzureTableStorage - Azure implementation
  • LogEntry, LogQuery - Data models
  • LogValidator - Input validation
  • Custom exceptions and DI extensions

Configuration Library (MasterZdran.Logging.Configuration)

  • Azure Key Vault configuration provider
  • Azure App Configuration provider
  • Configuration model with validation
  • Extension methods for easy setup

๐ŸŽฏ Common Scenarios

Distributed Tracing

// Automatically capture trace IDs from Activity
var traceId = Activity.Current?.Id ?? Guid.NewGuid().ToString();

logger.LogInformation("Processing request {RequestId}", requestId);
// TraceId is automatically captured from Activity.Current

Structured Logging

logger.LogInformation(
    "Order {OrderId} processed for user {UserId} with total {Amount:C}",
    orderId, userId, amount
);
// Structured data is automatically extracted

Exception Logging

try
{
    await ProcessOrderAsync(order);
}
catch (Exception ex)
{
    logger.LogError(ex, "Failed to process order {OrderId}", order.Id);
    // Exception details and stack trace are stored
}

Querying Logs

var logger = serviceProvider.GetRequiredService<AzureTableStorageLogger>();

var query = new LogQuery
{
    PageSize = 100,
    OrderBy = "Timestamp",
    Ascending = false,
    Filters = new Dictionary<string, object>
    {
        { "LogLevel", "Error" },
        { "LoggerName", "MyService" }
    }
};

var (logs, nextToken) = await logger.GetLogsAsync(query);

foreach (var log in logs)
{
    Console.WriteLine($"[{log.Level}] {log.Timestamp}: {log.Message}");
}

๐ŸŒ Azure Resources

The library integrates with:

  • Azure Table Storage - Log data persistence
  • Azure Key Vault - Secrets management (optional)
  • Azure App Configuration - Feature flags & settings (optional)
  • Azure Monitor - OpenTelemetry export (optional)
  • Azure Managed Identity - Authentication (optional)

Local Development

Use Azurite for local Azure Storage emulation:

# Install Azurite
npm install -g azurite

# Start Azurite
azurite-table

# Use in code
services.AddAzureTableStorageLogging(
    "UseDevelopmentStorage=true",
    "logs",
    "MyApp"
);

๐Ÿค Contributing

Contributions are welcome! Please see CONTRIBUTING.md for guidelines.

Building from Source

# Clone repository
git clone https://github.com/masterzdran/mz-logging-azure-tablestorage-csharp.git
cd mz-logging-azure-tablestorage-csharp

# Restore and build
dotnet restore
dotnet build

# Run tests
dotnet test

# Create NuGet packages
dotnet pack -c Release

๐Ÿ“„ License

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


๐Ÿ‘จโ€๐Ÿ’ป Author

Nuno Cancelo


๐Ÿ™ Acknowledgments


๐Ÿ“Š Project Stats

  • Lines of Code: ~3,500+
  • Tests: 114 (100% passing)
  • Code Coverage: High (unit + integration tests)
  • Target Frameworks: .NET 10.0, .NET 9.0, .NET 8.0, .NET 7.0
  • Dependencies: Minimal (Azure SDK, Microsoft.Extensions)
  • Documentation: 8 comprehensive guides


Ready to get started? Check out the Quick Start Guide!

Attribuition

<a href="https://www.flaticon.com/free-icons/log-file" title="log file icons">Log file icons created by Muhammad_Usman - Flaticon</a>

Product Compatible and additional computed target framework versions.
.NET net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  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 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 is compatible.  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
0.1.0 182 12/23/2025

Initial release with support for Azure Key Vault, Azure App Configuration, and standard .NET configuration sources.