Serilog.Enrichers.CallStack
1.0.25
See the version list below for details.
dotnet add package Serilog.Enrichers.CallStack --version 1.0.25
NuGet\Install-Package Serilog.Enrichers.CallStack -Version 1.0.25
<PackageReference Include="Serilog.Enrichers.CallStack" Version="1.0.25" />
<PackageVersion Include="Serilog.Enrichers.CallStack" Version="1.0.25" />
<PackageReference Include="Serilog.Enrichers.CallStack" />
paket add Serilog.Enrichers.CallStack --version 1.0.25
#r "nuget: Serilog.Enrichers.CallStack, 1.0.25"
#:package Serilog.Enrichers.CallStack@1.0.25
#addin nuget:?package=Serilog.Enrichers.CallStack&version=1.0.25
#tool nuget:?package=Serilog.Enrichers.CallStack&version=1.0.25
Serilog.Enrichers.CallStack
A Serilog enricher that adds call stack information to log events, including method names, file names, and line numbers. This enricher helps with debugging and tracing by providing detailed context about where log events originated.
Features
- Method Names: Capture the calling method name with optional parameter information
- Type Names: Include the declaring type name (class/struct) with optional namespace
- File Information: Add source file names with optional full paths
- Line Numbers: Include source code line numbers for precise location tracking
- Column Numbers: Optional column number information
- Assembly Names: Include assembly information when needed
- Flexible Configuration: Extensive configuration options for customization
- Exception Handling: Configurable exception handling to prevent logging failures
- Frame Filtering: Skip specific namespaces or types when walking the call stack
- Frame Offset: Choose which frame in the call stack to capture
Installation
dotnet add package Serilog.Enrichers.CallStack
Quick Start
Basic Usage
using Serilog;
using Serilog.Enrichers.CallStack;
var logger = new LoggerConfiguration()
.Enrich.WithCallStack()
.WriteTo.Console()
.CreateLogger();
logger.Information("Hello, world!");
This will produce log output similar to:
[15:30:45 INF] Hello, world! {MethodName="Main", TypeName="Program", FileName="Program.cs", LineNumber=12}
With Configuration
var logger = new LoggerConfiguration()
.Enrich.WithCallStack(config => config
.WithIncludes(methodName: true, typeName: true, fileName: true, lineNumber: true)
.WithFullNames(fullTypeName: true)
.WithMethodParameters(includeParameters: true)
.SkipNamespace("System")
.SkipNamespace("Microsoft"))
.WriteTo.Console()
.CreateLogger();
Configuration Options
Include/Exclude Information
var config = new CallStackEnricherConfiguration()
.WithIncludes(
methodName: true, // Include method names
typeName: true, // Include type names
fileName: true, // Include file names
lineNumber: true, // Include line numbers
columnNumber: false, // Include column numbers
assemblyName: false); // Include assembly names
Property Names
Customize the property names used in log events:
var config = new CallStackEnricherConfiguration()
.WithPropertyNames(
methodName: "Method",
typeName: "Class",
fileName: "File",
lineNumber: "Line",
columnNumber: "Column",
assemblyName: "Assembly");
Full vs. Short Names
Control whether to use full names (with namespaces/paths) or short names:
var config = new CallStackEnricherConfiguration()
.WithFullNames(
fullTypeName: true, // Use "MyApp.Services.UserService" vs "UserService"
fullFileName: true, // Use full path vs just filename
fullParameterTypes: true); // Use full type names in parameters
Method Parameters
Include method parameter information in the method name:
var config = new CallStackEnricherConfiguration()
.WithMethodParameters(
includeParameters: true,
useFullParameterTypes: false);
// Results in: "ProcessUser(String name, Int32 id)" instead of just "ProcessUser"
Skip Frames
Skip specific namespaces or types when walking the call stack:
var config = new CallStackEnricherConfiguration()
.SkipNamespace("System")
.SkipNamespace("Microsoft")
.SkipNamespace("Serilog")
.SkipType("MyApp.Infrastructure.LoggingWrapper");
Frame Offset
Choose which frame in the call stack to capture:
var config = new CallStackEnricherConfiguration()
.WithFrameOffset(1); // Skip 1 frame up the call stack
Exception Handling
Configure how exceptions during enrichment are handled:
var config = new CallStackEnricherConfiguration()
.WithExceptionHandling(
suppress: true, // Don't throw exceptions
onException: ex => Console.WriteLine($"Enricher error: {ex.Message}"));
Advanced Configuration Examples
Minimal Configuration
For production environments where you want minimal overhead:
var config = new CallStackEnricherConfiguration()
.WithIncludes(
methodName: true,
typeName: true,
fileName: false, // Skip file names to reduce overhead
lineNumber: false, // Skip line numbers
columnNumber: false,
assemblyName: false)
.WithFullNames(fullTypeName: false); // Use short type names
Development Configuration
For development environments where you want maximum detail:
var config = new CallStackEnricherConfiguration()
.WithIncludes(
methodName: true,
typeName: true,
fileName: true,
lineNumber: true,
columnNumber: true,
assemblyName: true)
.WithFullNames(
fullTypeName: true,
fullFileName: true,
fullParameterTypes: true)
.WithMethodParameters(includeParameters: true)
.WithExceptionHandling(suppress: false); // Throw exceptions for debugging
Filtering Configuration
Skip common framework types and focus on application code:
var config = new CallStackEnricherConfiguration()
.SkipNamespace("System")
.SkipNamespace("Microsoft")
.SkipNamespace("Serilog")
.SkipNamespace("Newtonsoft")
.SkipType("MyApp.Infrastructure.LoggingService")
.WithFrameOffset(0);
Integration with Different Sinks
Console Output
var logger = new LoggerConfiguration()
.Enrich.WithCallStack()
.WriteTo.Console(outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} " +
"({TypeName}.{MethodName} in {FileName}:{LineNumber}){NewLine}{Exception}")
.CreateLogger();
JSON Output (for structured logging)
var logger = new LoggerConfiguration()
.Enrich.WithCallStack()
.WriteTo.File(new JsonFormatter(), "log.json")
.CreateLogger();
Seq Integration
var logger = new LoggerConfiguration()
.Enrich.WithCallStack()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
Performance Considerations
- Debug vs Release: Call stack information is more accurate in Debug builds
- File/Line Info: Including file names and line numbers requires debug symbols
- Method Parameters: Including parameter information adds overhead
- Frame Skipping: Use skip configurations to avoid walking unnecessary frames
- Exception Handling: Enable exception suppression in production
Debug Symbols
For file names and line numbers to work properly, ensure your application is built with debug symbols:
<PropertyGroup>
<DebugType>portable</DebugType>
<DebugSymbols>true</DebugSymbols>
</PropertyGroup>
Example Output
With full configuration, log events will include rich call stack information:
{
"@t": "2024-01-15T15:30:45.123Z",
"@l": "Information",
"@m": "Processing user request",
"MethodName": "ProcessRequest(String userId, UserRequest request)",
"TypeName": "MyApp.Services.UserService",
"FileName": "UserService.cs",
"LineNumber": 45,
"ColumnNumber": 12,
"AssemblyName": "MyApp.Services"
}
Best Practices
- Use appropriate configuration for your environment: Detailed information for development, minimal for production
- Skip framework namespaces: Focus on your application code by skipping system namespaces
- Consider performance impact: Call stack walking has overhead, especially with full configuration
- Enable exception suppression in production: Prevent logging failures from breaking your application
- Use structured logging sinks: JSON-based sinks work best with the additional properties
Compatibility
- .NET Standard 2.0+: Compatible with .NET Framework 4.6.1+, .NET Core 2.0+, .NET 5+
- Serilog 3.0+: Requires Serilog version 3.0 or higher
License
This project is licensed under the MIT License - see the LICENSE file for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Changelog
Version 1.0.22 (2025-07-28)
- NuGet Publishing: Added automatic NuGet publishing workflow
- CI/CD: GitHub Actions integration for automated builds and publishing
Version 1.0.20 (2025-07-28)
- Stability: Resolved failing tests by improving frame detection and test expectations
- Bug Fix: Removed InMemorySink.Clear() call that caused compilation error
- Documentation: Updated project status to stable
Version 1.0.17 (2025-07-28)
- Release: Prepared v1.0.0 release candidate
- Testing: Improved test stability and isolation
- Performance: Enhanced stack trace frame processing optimization
Version 1.0.13 (2025-07-28)
- Documentation: Enhanced README with performance optimization notes
- Filtering: Improved namespace filtering documentation and functionality
Version 1.0.9 (2025-07-28)
- Performance: Optimized stack trace frame processing for high-throughput scenarios
- Testing: Enhanced testing framework and utilities
- Core Features: Improved CallStackEnricher exception handling
Version 1.0.4 (2025-07-28)
- Configuration: Enhanced CallStackEnricherConfiguration fluent API
- Core Functionality: Implemented core call stack enrichment functionality
Version 1.0.1 (2025-07-28)
- Initial Release: Project setup and solution structure
- Core Features: Basic call stack enrichment functionality
- Configuration: Comprehensive configuration options
- Documentation: Complete documentation and examples
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. 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 was computed. 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 was computed. 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. |
.NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
.NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
.NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
MonoAndroid | monoandroid was computed. |
MonoMac | monomac was computed. |
MonoTouch | monotouch was computed. |
Tizen | tizen40 was computed. tizen60 was computed. |
Xamarin.iOS | xamarinios was computed. |
Xamarin.Mac | xamarinmac was computed. |
Xamarin.TVOS | xamarintvos was computed. |
Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- Serilog (>= 3.0.1)
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 |
---|---|---|
1.0.358 | 34,535 | 8/26/2025 |
1.0.357 | 28,865 | 8/26/2025 |
1.0.356 | 19,086 | 8/26/2025 |
1.0.355 | 15,362 | 8/26/2025 |
1.0.354 | 8,025 | 8/26/2025 |
1.0.352 | 181 | 8/26/2025 |
1.0.351 | 177 | 8/26/2025 |
1.0.350 | 4,188 | 8/26/2025 |
1.0.200 | 183 | 8/26/2025 |
1.0.37 | 149 | 8/19/2025 |
1.0.36 | 134 | 8/19/2025 |
1.0.32 | 131 | 8/19/2025 |
1.0.28 | 124 | 7/29/2025 |
1.0.27 | 122 | 7/29/2025 |
1.0.26 | 112 | 7/28/2025 |
1.0.25 | 112 | 7/28/2025 |
1.0.24 | 105 | 7/28/2025 |
1.0.22 | 107 | 7/28/2025 |
1.0.2 | 128 | 8/19/2025 |
1.0.1 | 128 | 8/19/2025 |
Production ready release with comprehensive call stack enrichment functionality.