本文整理汇总了C#中Serilog.Events.LogEvent.RemovePropertyIfPresent方法的典型用法代码示例。如果您正苦于以下问题:C# LogEvent.RemovePropertyIfPresent方法的具体用法?C# LogEvent.RemovePropertyIfPresent怎么用?C# LogEvent.RemovePropertyIfPresent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serilog.Events.LogEvent
的用法示例。
在下文中一共展示了LogEvent.RemovePropertyIfPresent方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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()));
}
示例2: Emit
public void Emit(LogEvent logEvent)
{
var correctedLogEvent = logEvent;
if (logEvent.Properties.ContainsKey(Common.Constants.KeyPassportTimestamp))
{
var passportTimestampProperty = logEvent.Properties[Common.Constants.KeyPassportTimestamp];
if (passportTimestampProperty != null)
{
var passportTimestampValue = passportTimestampProperty as ScalarValue;
if (passportTimestampValue != null)
{
if (passportTimestampValue.Value is DateTimeOffset)
{
var passportTimestamp = (DateTimeOffset)passportTimestampValue.Value;
correctedLogEvent = new LogEvent(passportTimestamp
, logEvent.Level
, logEvent.Exception
, logEvent.MessageTemplate
, logEvent.Properties.Select(x => new LogEventProperty(x.Key, x.Value)).ToList()
);
correctedLogEvent.RemovePropertyIfPresent(Common.Constants.KeyPassportTimestamp);
}
}
}
}
_destination.Write(correctedLogEvent);
}