Muscula.Csharp.Extensions.Logging.Log4Net 2.0.0

dotnet add package Muscula.Csharp.Extensions.Logging.Log4Net --version 2.0.0
                    
NuGet\Install-Package Muscula.Csharp.Extensions.Logging.Log4Net -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.Log4Net" 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.Log4Net" Version="2.0.0" />
                    
Directory.Packages.props
<PackageReference Include="Muscula.Csharp.Extensions.Logging.Log4Net" />
                    
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.Log4Net --version 2.0.0
                    
#r "nuget: Muscula.Csharp.Extensions.Logging.Log4Net, 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.Log4Net@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.Log4Net&version=2.0.0
                    
Install as a Cake Addin
#tool nuget:?package=Muscula.Csharp.Extensions.Logging.Log4Net&version=2.0.0
                    
Install as a Cake Tool

Muscula.Csharp.Extensions.Logging.Log4Net

Overview

Muscula.Csharp.Extensions.Logging.Log4Net provides a custom Log4Net appender for integrating with Muscula error logging service. This package enables Log4Net-based applications to automatically send logs and exceptions to Muscula for centralized monitoring and analysis.

Features

  • Custom Log4Net Appender: Seamless integration with existing Log4Net configurations
  • Automatic Exception Tracking: Captures and formats exception details including stack traces
  • Severity Level Mapping: Maps Log4Net levels to Muscula severity levels
  • Structured Data Support: Support for custom structured data through MusculaException
  • Stack Trace Parsing: Automatic extraction of file names and line numbers from exceptions
  • Configuration via XML: Standard Log4Net XML configuration support

Installation

Install the package via NuGet:

dotnet add package Muscula.Csharp.Extensions.Logging.Log4Net

Or via Package Manager:

Install-Package Muscula.Csharp.Extensions.Logging.Log4Net

Quick Start

1. Add Log4Net to Your Application

In your Program.cs or Startup.cs:

services.AddLogging(builder => builder.AddLog4Net("log4net.config"));

2. Configure the Muscula Appender

Create or update your log4net.config file:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
    <appender name="MusculaAppender" type="Muscula.Csharp.Extensions.Logging.Log4Net.MusculaAppender, Muscula.Csharp.Extensions.Logging.Log4Net">
        <layout type="log4net.Layout.PatternLayout">
            <conversionPattern value="%date [%thread] %-5level %logger [%ndc] - %message%newline" />
        </layout>
        <MusculaSettings>
            <LogId value="YOUR_MUSCULA_LOG_ID" />
            <Url value="https://api.muscula.com" /> 
        </MusculaSettings>
    </appender>
    
    <root>
        <level value="ALL" />
        <appender-ref ref="MusculaAppender" />
    </root>
</log4net>

3. Use Log4Net in Your Code

public class MyService
{
    private static readonly ILog Logger = LogManager.GetLogger(typeof(MyService));

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

Level Mapping

The appender maps Log4Net levels to Muscula severity levels:

Log4Net Level Muscula Severity
Fatal Fatal
Error Error
Warn Warning
Info Info
Debug Debug

Advanced Usage

Logging with Structured Data

Use MusculaException to include structured data with your logs:

try
{
    // Your code
}
catch (Exception ex)
{
    var musculaEx = new MusculaException("Operation failed", ex)
    {
        StructuralData = new 
        {
            UserId = userId,
            OrderId = orderId,
            Timestamp = DateTime.UtcNow
        }
    };
    Logger.Error("Order processing failed", musculaEx);
}

Multiple Appenders

You can use MusculaAppender alongside other appenders:

<log4net>
    <appender name="MusculaAppender" type="Muscula.Csharp.Extensions.Logging.Log4Net.MusculaAppender, Muscula.Csharp.Extensions.Logging.Log4Net">
        
    </appender>
    
    <appender name="ConsoleAppender" type="log4net.Appender.ConsoleAppender">
        
    </appender>
    
    <root>
        <level value="ALL" />
        <appender-ref ref="MusculaAppender" />
        <appender-ref ref="ConsoleAppender" />
    </root>
</log4net>

Requirements

  • .NET 10.0 or higher
  • log4net 3.3.2 or higher
  • Muscula.Csharp.Extensions.Logging package
  • 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.

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
2.0.0 91 7/23/2026
1.1.2 322 8/25/2025
1.1.1 253 8/30/2023
1.1.0 554 10/15/2021
1.0.1 566 12/4/2020
1.0.0 662 9/15/2020