Exception Stack Trace detail stripped by sinks
See original GitHub issueI am trying to use Serilog (with Seq) to log unhandled exceptions in my application. I noticed that while the console log would contain a full stack trace including source filenames and line numbers, the exception written to seq would not. After some investigation, I believe this problem is related to the sink code, or it’s an issue with the Exception class in general.
Seq uses PeriodicBatchingSink
, and after stepping through the code in debug mode, I discovered that the logEvent.Exception property contains the full stack trace when it enters PeriodicBatchingSink.EmitBatch. As soon as it calls into the overridden method specific to the sink (SeqSink.EmitBatchAsync in this case), logEvent.Exception no longer contains the line number information (even if you view the variable from the previous caller in the call stack!).
I’m looking for a way to get this information passed through to Seq, preferably in the “proper” way - I’m using an enricher to serialise the stack trace into a second property at the moment as a workaround, but this is not ideal as my log message now contains two stack traces - one complete and one without line numbers.
Very simple sample program:
static void Main(string[] args)
{
Log.Logger = new LoggerConfiguration()
.WriteTo.ColoredConsole()
.WriteTo.Seq("http://localhost:5341")
.CreateLogger();
try
{
throw new NotImplementedException();
}
catch (Exception ex)
{
Log.Error(ex, "error caught");
}
}
This will cause a full stack trace to be printed to the console, but the version logged to Seq will only contain the function names - no file names or line numbers.
Issue Analytics
- State:
- Created 9 years ago
- Comments:12 (6 by maintainers)
I’m still having the issue where the linenumbers are missing in the stack info. My setup: Serilog (2.5.0) in conjunction with AutofacSerilogIntegration (2.0.0) and Seq (Serilog.Sinks.Seq 3.4.0). The linenumbers are both missing in the logfiles as in Seq. Reading the above comments I can’t see this issue was fixed.
Okay, thanks for the update Claire. I’ll close this one (again) but do please raise another if you find anything still amiss. Thanks!