Muscula.Csharp.Extensions.Logging 2.0.0

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

Muscula.Csharp.Extensions.Logging

Overview

Muscula.Csharp.Extensions.Logging is a .NET logging provider that integrates with Muscula - a comprehensive error logging and monitoring service for web applications and services. This package provides structured logging capabilities with built-in error tracking and analytics.

Features

  • Structured Logging: Support for logging structured data along with messages
  • Automatic Error Tracking: Seamlessly captures and reports exceptions
  • Performance Optimized: Asynchronous message batching for minimal performance impact
  • Severity Levels: Support for multiple log severity levels (Debug, Info, Warning, Error, Fatal)
  • Stack Trace Parsing: Automatic parsing and formatting of exception stack traces
  • Thread-Safe: Concurrent message queue processing

Installation

Install the package via NuGet:

dotnet add package Muscula.Csharp.Extensions.Logging

Or via Package Manager:

Install-Package Muscula.Csharp.Extensions.Logging

Quick Start

Basic Configuration

Configure Muscula logging in your Program.cs or Startup.cs:

services.AddLogging(builder => builder.AddMuscula(
    settingsBuilder =>
    {
        settingsBuilder.UseLogId("YOUR_MUSCULA_LOG_ID");
        return settingsBuilder.Build();
    }));

Using the Logger

Inject ILogger<T> into your classes:

public class MyService
{
    private readonly ILogger<MyService> _logger;

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

    public void DoWork()
    {
        _logger.LogInformation("Starting work");
        
        try
        {
            // Your code here
        }
        catch (Exception ex)
        {
            _logger.LogError(ex, "Error occurred during work");
        }
    }
}

Structured Logging

For more detailed logging with structured data:

public class OrderService
{
    private readonly IMusculaStructuralLogger _structuralLogger;

    public OrderService(IMusculaStructuralLogger structuralLogger)
    {
        _structuralLogger = structuralLogger;
    }

    public void ProcessOrder(Order order)
    {
        _structuralLogger.LogStructural(
            Severity.Info,
            message: "Processing order",
            structuralData: new { OrderId = order.Id, Amount = order.Total },
            className: nameof(OrderService)
        );
    }
}

Configuration Options

The MusculaSettingsBuilder provides various configuration options:

services.AddLogging(builder => builder.AddMuscula(
    settingsBuilder =>
    {
        settingsBuilder
            .UseLogId("YOUR_LOG_ID")
            .UseUrl("https://custom.endpoint.com") // Optional
            .UseEnvironment("production")          // Optional
            .UseRelease("1.4.2")                   // Optional
            .UseMaxBatchSize(50)                   // Optional, default 50
            .UseMaxLingerMs(1000)                  // Optional, default 1000
            .UseChannelCapacity(10_000)            // Optional, default 10000
            .UseConsumerCount(1);                  // Optional, default 1
        return settingsBuilder.Build();
    }));

Delivery tuning

The shipper buffers logs in a bounded in-memory channel and a single background consumer ships them in batches. The consumer stays fully blocked (zero CPU) while there is nothing to send, and wakes the instant a log is enqueued.

Option Default Description
UseMaxBatchSize 50 Max logs per POST. A full batch flushes immediately.
UseMaxLingerMs 1000 Max time (ms) a partial batch waits for more logs before shipping. Delivery latency is at most this plus network time.
UseChannelCapacity 10000 Max buffered logs. On overflow the newest log is dropped (never blocks the caller); dropped logs are counted in MusculaProvider.DroppedCount.
UseConsumerCount 1 Number of shipping consumers. Log shipping is I/O-bound; 1 is enough for almost all workloads.

Changelog

1.2.0

  • Idle CPU eliminated. The background sender is now fully event-driven: a bounded System.Threading.Channels.Channel feeds a single consumer that blocks on the channel and consumes no CPU while idle, instead of the previous timer/polling loop. On an idle host the SDK's CPU contribution is effectively 0 (measured < 1 mvCPU), so Azure Container Apps replicas can return to the billed idle rate.
  • Batching now uses a per-batch linger window (MaxLingerMs) that only exists while logs are pending - no permanent heartbeat.
  • Bounded channel with drop-on-overflow (ChannelCapacity) so a log burst can never block callers or exhaust memory; dropped logs are counted in MusculaProvider.DroppedCount.
  • Reused HttpClient over a pooled SocketsHttpHandler; send retries now use exponential backoff with jitter.
  • Deterministic flush on host shutdown via a registered IHostedService; buffered logs are drained (bounded timeout) so shutdown does not lose logs.
  • New tuning knobs: MaxBatchSize, MaxLingerMs, ChannelCapacity, ConsumerCount.
  • The public API is unchanged: builder.Logging.AddMuscula(s => s.UseLogId(id).Build()) still works as before.

Requirements

  • .NET 10.0 or higher
  • Active Muscula account with valid Log ID

Support

For issues and questions:

License

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

Product Compatible and additional computed target framework versions.
.NET 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.
  • net10.0

    • No dependencies.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Muscula.Csharp.Extensions.Logging:

Package Downloads
Muscula.Csharp.Extensions.Logging.AspNetCore

Package Description

Muscula.Csharp.Extensions.Logging.Log4Net

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
2.0.2 57 8/3/2026
2.0.0 374 7/23/2026
1.1.2 1,982 8/25/2025
1.1.1 4,609 8/30/2023
1.1.0 10,317 10/15/2021
1.0.1 2,027 12/4/2020
1.0.0 797 9/15/2020