本文整理汇总了C#中Serilog.Events.LogEvent.AddPropertyIfAbsent方法的典型用法代码示例。如果您正苦于以下问题:C# LogEvent.AddPropertyIfAbsent方法的具体用法?C# LogEvent.AddPropertyIfAbsent怎么用?C# LogEvent.AddPropertyIfAbsent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Serilog.Events.LogEvent
的用法示例。
在下文中一共展示了LogEvent.AddPropertyIfAbsent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var rnd = new Random();
int fakeTenantId = rnd.Next(1, 20);
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("RequestId", Guid.NewGuid().ToString("N")));
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("TenantId", fakeTenantId));
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("UserId", "Annonymous Koala"));
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Version", "1.0")); // in real life, you would get this from the DLL
}
示例2: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent.Exception != null)
{
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ExceptionDetail", this.DestructureException(logEvent.Exception), true));
}
}
示例3: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (propertyFactory == null) throw new ArgumentNullException("propertyFactory");
var property = propertyFactory.CreateProperty(_name, _value, _destructureObjects);
logEvent.AddPropertyIfAbsent(property);
}
示例4: Enrich
public void Enrich(LogEvent logEvent)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (HttpContext.Current == null)
return;
int requestId;
var requestIdItem = HttpContext.Current.Items[RequestIdItemName];
if (requestIdItem == null)
HttpContext.Current.Items[RequestIdItemName] = requestId = Interlocked.Increment(ref LastRequestId);
else
requestId = (int)requestIdItem;
string sessionId = null;
if (HttpContext.Current.Session != null)
sessionId = HttpContext.Current.Session.SessionID;
logEvent.AddPropertyIfAbsent(
LogEventProperty.For(HttpRequestPropertyName,
new
{
SessionId = sessionId,
Id = requestId,
},
destructureObjects: true));
}
示例5: Enrich
/// <summary>
/// Enrich the log event with the current ASP.NET user name, if User.Identity.IsAuthenticated is true.</summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null)
throw new ArgumentNullException("logEvent");
var userName = _noneUsername;
if (HttpContext.Current != null)
{
var context = new HttpContextWrapper(HttpContext.Current);
if (context.User != null)
{
if (context.User.Identity == null || context.User.Identity.IsAuthenticated == false)
{
if (_anonymousUsername != null)
userName = _anonymousUsername;
}
else
{
userName = context.User.Identity.Name;
}
}
}
if (userName == null)
return;
var userNameProperty = new LogEventProperty(UserNamePropertyName, new ScalarValue(userName));
logEvent.AddPropertyIfAbsent(userNameProperty);
}
示例6: Enrich
/// <summary>
/// Enrich the log event.
/// </summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
#if !ASPNETCORE50
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(MachineNamePropertyName, Environment.MachineName);
#else
_cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(MachineNamePropertyName, Environment.GetEnvironmentVariable("COMPUTERNAME"));
#endif
logEvent.AddPropertyIfAbsent(_cachedProperty);
}
示例7: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var userName = HttpContext.Current == null || HttpContext.Current.User == null || HttpContext.Current.User.Identity == null
? "NoUserContext"
: HttpContext.Current.User.Identity.Name;
logEvent.AddPropertyIfAbsent(
propertyFactory.CreateProperty("UserName", userName));
}
示例8: Enrich
/// <summary>
/// Enriches the log event.
/// </summary>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent.Exception == null)
return;
var readableStackTrace = propertyFactory.CreateProperty(
"ReadableStackTrace",
logEvent.Exception.ToAsyncString(),
destructureObjects: true);
logEvent.AddPropertyIfAbsent(readableStackTrace);
var fullExceptionString = propertyFactory.CreateProperty(
"FullExceptionString",
logEvent.Exception.ToString(),
destructureObjects: true);
logEvent.AddPropertyIfAbsent(fullExceptionString);
}
示例9: Enrich
/// <summary>
/// Enrich the log event.
/// </summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (propertyFactory == null) throw new ArgumentNullException("propertyFactory");
foreach (var property in _properties)
{
logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(property.Key,
property.Value,
_destructureObjects));
}
}
示例10: Enrich
/// <summary>
/// Enrich the log event with an id assigned to the currently-executing HTTP request, if any.
/// </summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (HttpContext.Current == null)
return;
var serviceProvider = (IServiceProvider)HttpContext.Current;
var workerReqest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
var requestId = workerReqest.RequestTraceIdentifier;
var requestIdProperty = new LogEventProperty(HttpRequestTraceIdPropertyName, new ScalarValue(requestId));
logEvent.AddPropertyIfAbsent(requestIdProperty);
}
示例11: Enrich
/// <summary>
/// Enrich the log event.
/// </summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (HttpContextCurrent.Request == null)
return;
if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.UserHostName))
return;
var userHostName = HttpContextCurrent.Request.UserHostName;
var httpRequestClientHostnameProperty = new LogEventProperty(HttpRequestClientHostNamePropertyName, new ScalarValue(userHostName));
logEvent.AddPropertyIfAbsent(httpRequestClientHostnameProperty);
}
示例12: Enrich
/// <summary>
/// Enrich the log event with the current ASP.NET session id, if sessions are enabled.</summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (HttpContext.Current == null)
return;
if (HttpContext.Current.Session == null)
return;
var sessionId = HttpContext.Current.Session.SessionID;
var sesionIdProperty = new LogEventProperty(HttpSessionIdPropertyName, new ScalarValue(sessionId));
logEvent.AddPropertyIfAbsent(sesionIdProperty);
}
示例13: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
for (var scope = CurrentScope; scope != null; scope = scope.Parent)
{
var stateStructure = scope.State as ILogValues;
if (stateStructure != null)
{
foreach (var keyValue in stateStructure.GetValues())
{
var property = propertyFactory.CreateProperty(keyValue.Key, keyValue.Value);
logEvent.AddPropertyIfAbsent(property);
}
}
}
}
示例14: Enrich
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
var experiment = string.Empty;
try
{
experiment = ExperimentManager.GetCurrentExperiment();
}
catch (Exception e)
{
experiment = "Failed: " + e.Message;
}
logEvent.AddPropertyIfAbsent(
propertyFactory.CreateProperty("Experiment", experiment));
}
示例15: Enrich
/// <summary>
/// Enrich the log event.
/// </summary>
/// <param name="logEvent">The log event to enrich.</param>
/// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
{
if (logEvent == null) throw new ArgumentNullException("logEvent");
if (HttpContext.Current == null)
return;
if (HttpContextCurrent.Request == null)
return;
if (HttpContextCurrent.Request.UrlReferrer == null)
return;
var requestUrlReferrer = HttpContextCurrent.Request.UrlReferrer.ToString();
var httpRequestUrlReferrerProperty = new LogEventProperty(HttpRequestUrlReferrerPropertyName, new ScalarValue(requestUrlReferrer));
logEvent.AddPropertyIfAbsent(httpRequestUrlReferrerProperty);
}