public void Enrich(Serilog.Events.LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { var traceId = StringUtil.DecodeBase64ToUTF8(_httpContextAccessor.HttpContext.Request.Headers[Constants.TraceIdHeader].ToString()); var userSessionId = StringUtil.DecodeBase64ToUTF8(_httpContextAccessor.HttpContext.Request.Headers[Constants.UserSessionIdHeader].ToString()); logEvent.AddPropertyIfAbsent(new LogEventProperty("TraceId", new ScalarValue(traceId))); logEvent.AddPropertyIfAbsent(new LogEventProperty("UserSessionId", new ScalarValue(userSessionId))); }
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 }
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)); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { if (logEvent.Exception != null) { logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ExceptionDetail", this.DestructureException(logEvent.Exception), true)); } }
/// <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); }
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); }
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)); }
/// <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); }
/// <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); }
/// <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)); } }
/// <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); }
/// <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); }
/// <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); }
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); } } } }
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)); }
/// <summary> /// Enrich the log event with the number 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; int requestNumber; var requestNumberItem = HttpContext.Current.Items[RequestNumberItemName]; if (requestNumberItem == null) HttpContext.Current.Items[RequestNumberItemName] = requestNumber = Interlocked.Increment(ref LastRequestNumber); else requestNumber = (int)requestNumberItem; var requestNumberProperty = new LogEventProperty(HttpRequestNumberPropertyName, new ScalarValue(requestNumber)); logEvent.AddPropertyIfAbsent(requestNumberProperty); }
/// <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; Guid requestId; var requestIdItem = HttpContext.Current.Items[RequestIdItemName]; if (requestIdItem == null) HttpContext.Current.Items[RequestIdItemName] = requestId = Guid.NewGuid(); else requestId = (Guid)requestIdItem; var requestIdProperty = new LogEventProperty(HttpRequestIdPropertyName, new ScalarValue(requestId)); logEvent.AddPropertyIfAbsent(requestIdProperty); }
/// <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 (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.RawUrl)) return; var requestRawUrl = HttpContextCurrent.Request.RawUrl; var httpRequestRawUrlProperty = new LogEventProperty(HttpRequestRawUrlPropertyName, new ScalarValue(requestRawUrl)); logEvent.AddPropertyIfAbsent(httpRequestRawUrlProperty); }
/// <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); }
/// <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) { var properties = new List<LogEventProperty> { _cachedProperties.GetOrAdd("MachineName", k => propertyFactory.CreateProperty(k, Environment.MachineName)), _cachedProperties.GetOrAdd("Is64BitOperatingSystem", k => propertyFactory.CreateProperty(k, Environment.Is64BitOperatingSystem)), _cachedProperties.GetOrAdd("OSVersion", k => propertyFactory.CreateProperty(k, Environment.OSVersion)), _cachedProperties.GetOrAdd("ProcessorCount", k => propertyFactory.CreateProperty(k, Environment.ProcessorCount)), _cachedProperties.GetOrAdd(".NETVersion", k => propertyFactory.CreateProperty(k, Environment.Version)) }; foreach (var p in properties) { logEvent.AddPropertyIfAbsent(p); } }
/// <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 (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.UserHostAddress)) return; string userHostAddress; // Taking Proxy/-ies into consideration, too (if wanted and available) if (CheckForHttpProxies) { userHostAddress = !string.IsNullOrWhiteSpace(HttpContextCurrent.Request.ServerVariables["HTTP_X_FORWARDED_FOR"]) ? HttpContextCurrent.Request.ServerVariables["HTTP_X_FORWARDED_FOR"] : HttpContextCurrent.Request.UserHostAddress; } else { userHostAddress = HttpContextCurrent.Request.UserHostAddress; } if (string.IsNullOrWhiteSpace(userHostAddress)) return; // As multiple proxies can be in place according to header spec (see http://en.wikipedia.org/wiki/X-Forwarded-For), we check for it and only extract the first address (which 'should' be the actual client one) if (userHostAddress.Contains(",")) { userHostAddress = userHostAddress.Split(',').First().Trim(); } var httpRequestClientHostIPProperty = new LogEventProperty(HttpRequestClientHostIPPropertyName, new ScalarValue(userHostAddress)); logEvent.AddPropertyIfAbsent(httpRequestClientHostIPProperty); }
/// <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) { logEvent.AddPropertyIfAbsent(new LogEventProperty(ThreadIdPropertyName, new ScalarValue(Thread.CurrentThread.ManagedThreadId))); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Username", _user.Username)); logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ComputerName", _user.Lab)); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Component", "global")); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { logEvent.AddPropertyIfAbsent(logEvent.Properties.Keys.Contains("SourceContext") ? propertyFactory.CreateProperty("Source", logEvent.Properties["SourceContext"].ToString().Replace("\"", "").Split('.').Last()) : propertyFactory.CreateProperty("Source", "n/a")); }
/// <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) { _cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(TagPropertyName, TagPropertyValue); logEvent.AddPropertyIfAbsent(_cachedProperty); }
public void Enrich(LogEvent logEvent) { logEvent.AddPropertyIfAbsent("ThreadId", Thread.CurrentThread.ManagedThreadId); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { if (logEvent == null) throw new ArgumentNullException(nameof(logEvent)); logEvent.AddPropertyIfAbsent(_logEventProperty); }
/// <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) { _cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(ProcessIdPropertyName, Process.GetCurrentProcess().Id); logEvent.AddPropertyIfAbsent(_cachedProperty); }
/// <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) { _cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(MachineNamePropertyName, Environment.MachineName); logEvent.AddPropertyIfAbsent(_cachedProperty); }
public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) { logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(_propertyName, _source.FullyQualifiedName)); }