本文整理汇总了C#中Serilog.Events.LogEvent.AddOrUpdateProperty方法的典型用法代码示例。如果您正苦于以下问题:C# LogEvent.AddOrUpdateProperty方法的具体用法?C# LogEvent.AddOrUpdateProperty怎么用?C# LogEvent.AddOrUpdateProperty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serilog.Events.LogEvent
的用法示例。
在下文中一共展示了LogEvent.AddOrUpdateProperty方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
const string prefix = "NimbusMessage.";
var message = DispatchLoggingContext.NimbusMessage;
if (message == null) return;
logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty($"{prefix}MessageType", message.Payload?.GetType().FullName));
foreach (var property in typeof (NimbusMessage).GetProperties())
{
if (property.Name == nameof(NimbusMessage.Payload)) continue;
logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty($"{prefix}{property.Name}", property.GetValue(message)));
}
}
示例2: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory factory)
{
var trace = new StackTrace();
const int index = 5;
if (trace.FrameCount < index)
{
logEvent.RemovePropertyIfPresent("ClassName");
logEvent.RemovePropertyIfPresent("MethodName");
return;
}
var method = trace.GetFrame(index).GetMethod();
logEvent.AddOrUpdateProperty(factory.CreateProperty("ClassName", method.ReflectedType));
logEvent.AddOrUpdateProperty(factory.CreateProperty("MethodName", method.ToString()));
}
示例3: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var testProperties = TestContext.CurrentContext?.Test.Properties;
if (testProperties == null) return;
if (!testProperties.Contains("TestId")) return;
logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("TestId", new ScalarValue(testProperties["TestId"])));
}
示例4: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory factory)
{
var messageContext = MessageContext.Current;
if (messageContext == null) return;
var correlationid = messageContext
.TransportMessage.Headers
.GetValueOrNull(Headers.CorrelationId);
if (correlationid == null) return;
logEvent.AddOrUpdateProperty(factory.CreateProperty(_propertyName, correlationid));
}
示例5: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
try
{
var testName = TestContext.CurrentContext?.Test.FullName;
if (testName == null) return;
logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("TestName", new ScalarValue(testName)));
}
catch
{
// NUnit throws internal NullReferenceExceptions sometimes when we try to fetch
// the test details :(
}
}
示例6: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null)
throw new ArgumentNullException("logEvent");
if (logEvent.Exception != null)
{
var exceptionType = logEvent.Exception.GetType();
var nestedProperties = exceptionType.GetProperties().Select(
x => CreateLogProperty(x.Name, x.GetValue(logEvent.Exception, null))).ToList();
nestedProperties.Add(CreateLogProperty("Type", exceptionType));
logEvent.AddOrUpdateProperty(
new LogEventProperty(ExceptionPropertyName, new DictionaryValue(nestedProperties)));
}
}
示例7: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var frames = new StackTrace().GetFrames();
Func<StackFrame, bool> serilogFrames =
stack =>
stack.GetMethod()
.DeclaringType
.Namespace
.StartsWith("serilog.core", StringComparison.InvariantCultureIgnoreCase);
var serilogFrameCount = frames.Count(serilogFrames);
var callerFrame = frames.Skip(serilogFrameCount + 1).First();
var method = callerFrame.GetMethod().Name;
var caller = callerFrame.GetMethod().DeclaringType.FullName;
var property = propertyFactory.CreateProperty("LogCaller",
new LogCaller {ClassName = caller, Method = method});
logEvent.AddOrUpdateProperty(property);
}
示例8: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("InstanceId", RoleEnvironment.CurrentRoleInstance.Id));
}
示例9: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var prop = propertyFactory.CreateProperty("User", _identity);
logEvent.AddOrUpdateProperty(prop);
}