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
<PackageReference Include="Muscula.Csharp.Extensions.Logging.Log4Net" Version="2.0.0" />
<PackageVersion Include="Muscula.Csharp.Extensions.Logging.Log4Net" Version="2.0.0" />
<PackageReference Include="Muscula.Csharp.Extensions.Logging.Log4Net" />
paket add Muscula.Csharp.Extensions.Logging.Log4Net --version 2.0.0
#r "nuget: Muscula.Csharp.Extensions.Logging.Log4Net, 2.0.0"
#:package Muscula.Csharp.Extensions.Logging.Log4Net@2.0.0
#addin nuget:?package=Muscula.Csharp.Extensions.Logging.Log4Net&version=2.0.0
#tool nuget:?package=Muscula.Csharp.Extensions.Logging.Log4Net&version=2.0.0
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:
- Visit Muscula Documentation
- Create an issue in the GitHub repository
License
This project is licensed under the MIT License - see the LICENSE file for details.
| Product | Versions 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. |
-
net10.0
- log4net (>= 3.3.2)
- Muscula.Csharp.Extensions.Logging (>= 2.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.