示例#1
0
        public void ShouldPassAlongAdditionalContext()
        {
            var traceId  = Guid.NewGuid();
            var spanId   = Guid.NewGuid();
            var context1 = _loggingAdapter.ForContext("traceId", traceId);
            var context2 = context1.ForContext("spanId", spanId);

            _sink.Clear();
            AwaitCondition(() => _sink.Writes.Count == 0);

            context1.Info("hi");
            AwaitCondition(() => _sink.Writes.Count == 1);

            _sink.Writes.TryDequeue(out var logEvent).Should().BeTrue();
            logEvent.Level.Should().Be(LogEventLevel.Information);
            logEvent.Properties.ContainsKey("traceId").Should().BeTrue();
            logEvent.Properties["traceId"].ToString().Should().BeEquivalentTo(traceId.ToString());

            _sink.Clear();
            AwaitCondition(() => _sink.Writes.Count == 0);

            context2.Info("bye");

            AwaitCondition(() => _sink.Writes.Count == 1);

            _sink.Writes.TryDequeue(out var logEvent2).Should().BeTrue();

            logEvent2.Level.Should().Be(LogEventLevel.Information);

            // needs to still have the context from context1
            logEvent2.Properties.ContainsKey("traceId").Should().BeTrue();
            logEvent2.Properties["traceId"].ToString().Should().BeEquivalentTo(traceId.ToString());

            // and its own context from context2
            logEvent2.Properties.ContainsKey("spanId").Should().BeTrue();
            logEvent2.Properties["spanId"].ToString().Should().BeEquivalentTo(spanId.ToString());
        }
示例#2
0
 /// <summary>
 /// Assigns a string to the Identity logging property
 /// </summary>
 /// <param name="actorContext">An Actor Context</param>
 /// <param name="identity">Identity string</param>
 /// <returns></returns>
 public static ILoggingAdapter WithIdentity(this ILoggingAdapter loggingAdapter, string identity)
 {
     return(loggingAdapter.ForContext(Identity, identity, true));
 }
示例#3
0
 /// <summary>
 /// Adds a value to a given property
 /// </summary>
 /// <param name="adapter"></param>
 /// <param name="propertyName"></param>
 /// <param name="value"></param>
 /// <param name="destructureObjects"></param>
 /// <returns></returns>
 private static ILoggingAdapter WithProperty(this ILoggingAdapter adapter, string propertyName, object value, bool destructureObjects = false)
 => adapter.ForContext(propertyName, value, destructureObjects) as SerilogLoggingAdapter;
            private readonly ILoggingAdapter _logger = Context.GetLogger <SerilogLoggingAdapter>(); // correct

            protected override void OnReceive(object message)
            {
                _logger.ForContext("semantic", true);
                _logger.Info("My boss makes me use {msg} logging", message);
            }