public void TestKeyReservation() { lock (_keyReservations) { _keyReservations.Clear(); _prefixReservations.Clear(); } Guid reservation = Guid.NewGuid(); string key = "My test key"; string key2 = LogContext.ReserveKey(key, reservation); Assert.AreEqual(key, key2); Guid r2; Assert.IsTrue(_keyReservations.TryGetValue(key, out r2)); Assert.AreEqual(reservation, r2); string value = Tester.RandomGenerator.RandomString(); LogContext context = new LogContext(); context.Set(reservation, key, value); Assert.IsNotNull(context); string value2 = context.Get(key); Assert.AreEqual(value, value2); }
protected override void Append(StringBuilder builder, LogEventInfo logEvent) { if (LogContext.Contains(Key) == false) { return; } var value = LogContext.Get <object>(Key); if (value is string && string.IsNullOrEmpty(Format)) { builder.Append(value); return; } var formatProvider = logEvent.FormatProvider; if (Format == "@") { ConfigurationItemFactory.Default.ValueFormatter.FormatValue(value, null, CaptureType.Serialize, formatProvider, builder); return; } if (value == null) { return; } ConfigurationItemFactory.Default.ValueFormatter.FormatValue(value, Format, CaptureType.Normal, formatProvider, builder); }
public Log Get(int LogId) { return(_logContext.Get(LogId)); }