Пример #1
0
        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}");
                    }
                }
        }
Пример #2
0
        public CaptureOriginContextTests()
        {
            ThrowContextEnricher.EnsureInitialized();

            _log = new LoggerConfiguration()
                   .Enrich.FromLogContext()
                   .WriteTo.Sink(new DelegatingSink(e => _lastEvent = e))
                   .CreateLogger();
        }
Пример #3
0
        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));
        }