Fluent extensions for Microsoft.Extensions.Logging that capture caller file, member, and line information and prepend it to your log messages.
- From NuGet:
dotnet add package FluentLoggerExtensions - Or reference the project directly in your solution.
using FluentLogger;
using Microsoft.Extensions.Logging;
var logger = loggerFactory.CreateLogger<Program>();
logger.WithCaller().LogInformation("Processing {RequestId}", requestId);
// Logs something like: [Program.cs:Main:42] Processing 12345
logger.WithCaller().LogError("Failed to process {RequestId}: {Reason}", requestId, reason);ILogger.WithCaller([CallerFilePath] file, [CallerMemberName] member, [CallerLineNumber] line)returns aCallerLogContextwith captured caller info.CallerLogContext.LogInformation|LogWarning|LogError|LogDebuglog with a[{File}:{Member}:{Line}]prefix while preserving structured logging args.
- Target framework:
netstandard2.0 - Dependency:
Microsoft.Extensions.Logging.Abstractions (8.0.0)
- Build:
dotnet build(the project is configured to generate a NuGet package and symbols on build).
MIT