private static void Example3() { Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Console(new RenderedCompactJsonFormatter()) .CreateLogger(); ThrowContextEnricher.EnsureInitialized(); using (LogContext.PushProperty("A", "outer")) try { using (LogContext.PushProperty("A", "inner")) { throw new Exception(); } } catch (Exception ex) { using (LogContext.Push(new ThrowContextEnricher())) { Log.Error(ex, "Value of A is {A}"); } } }
public CaptureOriginContextTests() { ThrowContextEnricher.EnsureInitialized(); _log = new LoggerConfiguration() .Enrich.FromLogContext() .WriteTo.Sink(new DelegatingSink(e => _lastEvent = e)) .CreateLogger(); }
public FrameworkLoggerTests() { ThrowContextEnricher.EnsureInitialized(); _serilogLogger = new LoggerConfiguration() .Enrich.FromLogContext() .Enrich.With <ThrowContextEnricher>() .WriteTo.Sink(new DelegatingSink(e => _lastEvent = e)) .CreateLogger(); _frameworkLogger = new SerilogLoggerProvider(_serilogLogger) .CreateLogger(nameof(FrameworkLoggerTests)); }