Ejemplo n.º 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}");
                    }
                }
        }
Ejemplo n.º 2
0
        public CaptureOriginContextTests()
        {
            ThrowContextEnricher.EnsureInitialized();

            _log = new LoggerConfiguration()
                   .Enrich.FromLogContext()
                   .WriteTo.Sink(new DelegatingSink(e => _lastEvent = e))
                   .CreateLogger();
        }
Ejemplo n.º 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));
        }