Serilog.Enrichers.CallStack
1.0.351
See the version list below for details.
dotnet add package Serilog.Enrichers.CallStack --version 1.0.351
NuGet\Install-Package Serilog.Enrichers.CallStack -Version 1.0.351
<PackageReference Include="Serilog.Enrichers.CallStack" Version="1.0.351" />
<PackageVersion Include="Serilog.Enrichers.CallStack" Version="1.0.351" />
<PackageReference Include="Serilog.Enrichers.CallStack" />
paket add Serilog.Enrichers.CallStack --version 1.0.351
#r "nuget: Serilog.Enrichers.CallStack, 1.0.351"
#:package Serilog.Enrichers.CallStack@1.0.351
#addin nuget:?package=Serilog.Enrichers.CallStack&version=1.0.351
#tool nuget:?package=Serilog.Enrichers.CallStack&version=1.0.351
Serilog.Enrichers.CallStack
A Serilog enricher that adds call stack information to log events in an exception-like format. This enricher helps with debugging and tracing by providing detailed context about where log events originated, displaying the call stack in an intuitive format similar to exception stack traces.
Features
- Exception-like Format: Display call stack in familiar format:
Method:Line --> Method:Line --> Method:Line
- Single Property: Consolidates call stack into one
CallStack
property for cleaner logs - Configurable Depth: Control the number of frames to include (default: 5)
- Method Parameters: Optional parameter information in method names
- Type Information: Include declaring type names with optional namespace
- Line Numbers: Precise source code line numbers for exact location tracking
- Backward Compatibility: Legacy format with individual properties still available
- Frame Filtering: Skip specific namespaces or types when walking the call stack
- Exception Handling: Configurable exception handling to prevent logging failures
- Flexible Configuration: Extensive configuration options for customization
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! {CallStack="Program.Main:12 --> Program.<Main>$:8"}
Exception-like Format (Default)
var logger = new LoggerConfiguration()
.Enrich.WithCallStack(config => config
.WithCallStackFormat(useExceptionLikeFormat: true, maxFrames: 3)
.WithMethodParameters(includeParameters: true)
.WithFullNames(fullTypeName: false)
.SkipNamespace("System")
.SkipNamespace("Microsoft"))
.WriteTo.Console(outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} | {CallStack}{NewLine}{Exception}")
.CreateLogger();
Legacy Format
var logger = new LoggerConfiguration()
.Enrich.WithCallStack(config => config
.WithCallStackFormat(useExceptionLikeFormat: false) // Use individual properties
.WithIncludes(methodName: true, typeName: true, fileName: true, lineNumber: true)
.WithFullNames(fullTypeName: true)
.WithMethodParameters(includeParameters: true))
.WriteTo.Console()
.CreateLogger();
Configuration Options
Call Stack Format
Choose between the new exception-like format or legacy individual properties:
var config = new CallStackEnricherConfiguration()
.WithCallStackFormat(
useExceptionLikeFormat: true, // Default: true
maxFrames: 5, // Default: 5, -1 for unlimited
callStackPropertyName: "CallStack"); // Default: "CallStack"
Exception-like Format Output:
CallStack: "UserService.ProcessUser:45 --> UserController.CreateUser:23 --> Program.Main:12"
Legacy Format Output:
MethodName: "ProcessUser", TypeName: "UserService", FileName: "UserService.cs", LineNumber: 45
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 with Exception-like Format
var logger = new LoggerConfiguration()
.Enrich.WithCallStack()
.WriteTo.Console(outputTemplate:
"[{Timestamp:HH:mm:ss} {Level:u3}] {Message:lj} | Call Stack: {CallStack}{NewLine}{Exception}")
.CreateLogger();
Console Output with Legacy Format
var logger = new LoggerConfiguration()
.Enrich.WithCallStack(config => config.WithCallStackFormat(useExceptionLikeFormat: false))
.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
Exception-like Format (Default)
With the new exception-like format, log events include a single CallStack property:
{
"@t": "2025-07-29T00:30:45.123Z",
"@l": "Information",
"@m": "Processing user request",
"CallStack": "UserService.ProcessRequest(String userId, UserRequest request):45 --> UserController.CreateUser:23 --> Program.Main:12"
}
Legacy Format
When using legacy format (useExceptionLikeFormat: false
), individual properties are included:
{
"@t": "2025-07-29T00: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 exception-like format for readability: The default format provides intuitive call stack traces
- Limit frame depth in production: Use
maxFrames
to control overhead (default: 5 frames) - Skip framework namespaces: Focus on your application code by skipping system namespaces
- Consider performance impact: Call stack walking has overhead, tune
maxFrames
accordingly - Enable exception suppression in production: Prevent logging failures from breaking your application
- Use structured logging sinks: JSON-based sinks work best with the call stack properties
- Choose appropriate format: Exception-like for debugging, legacy for detailed property access
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. // Change: 2025-08-26 16:11:41.617678
// Change: 2025-08-26 16:11:41.956905
// Change: 2025-08-26 16:11:42.536687
// Change: 2025-08-26 16:13:11.637531
// Change: 2025-08-26 16:13:12.865531
// Change: 2025-08-26 16:13:14.853527
// Change: 2025-08-26 16:13:15.852438
// Change: 2025-08-26 16:13:17.157703
// Change: 2025-08-26 16:13:17.324593
// Change: 2025-08-26 16:13:18.730064
// Change: 2025-08-26 16:13:27.203322
// Change: 2025-08-26 16:13:29.229617
// Change: 2025-08-26 16:13:30.209719
// Change: 2025-08-26 16:13:30.858553
// Change: 2025-08-26 16:13:31.439548
// Change: 2025-08-26 16:13:32.832075
// Change: 2025-08-26 16:13:33.066244
// Change: 2025-08-26 16:13:34.956034
// Change: 2025-08-26 16:13:39.860658
// Change: 2025-08-26 16:13:41.134807
// Change: 2025-08-26 16:13:43.552156
// Change: 2025-08-26 16:13:47.030141
// Change: 2025-08-26 16:13:50.115904
// Change: 2025-08-26 16:13:50.387044
// Change: 2025-08-26 16:13:52.385792
// Change: 2025-08-26 16:13:53.789561
// Change: 2025-08-26 16:13:55.492943
// Change: 2025-08-26 16:13:58.610873
// Change: 2025-08-26 16:14:00.495831
// Change: 2025-08-26 16:14:01.592282
// Change: 2025-08-26 16:14:02.633167
// Change: 2025-08-26 16:14:03.427792
// Enhancement: 2025-08-26 17:00:02.927883
// Enhancement: 2025-08-26 17:00:04.482214
// Enhancement: 2025-08-26 17:00:05.141315
// Enhancement: 2025-08-26 17:00:05.499076
// Enhancement: 2025-08-26 17:00:08.082284
// Enhancement: 2025-08-26 17:00:08.383449
// Enhancement: 2025-08-26 17:00:10.400175
// Enhancement: 2025-08-26 17:00:13.692241
// Enhancement: 2025-08-26 17:00:18.972545
// Enhancement: 2025-08-26 17:00:19.763993
// Enhancement: 2025-08-26 17:00:36.141750
// Enhancement: 2025-08-26 17:00:49.291630
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 | 31,317 | 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 |
Major feature release: Exception-like call stack format with single CallStack property, configurable depth, and backward compatibility with legacy format.