public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var newprop = $"[{logEvent.Level.ToString()}]";

            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(nameof(StandardLengthLevelName), newprop));
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("UtcTimestamp", logEvent.Timestamp.UtcDateTime));
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var sensitiveProperties = logEvent.Properties
                                      .Select(p => CreateSensitiveProperty(p.Key, p.Value))
                                      .Where(p => p != null)
                                      .ToDictionary(p => p.Name);

            if (!sensitiveProperties.Any())
            {
                return;
            }

            foreach (var property in logEvent.Properties.Where(p => sensitiveProperties.ContainsKey(p.Key)).ToList())
            {
                var safeProperty = CreateSafeProperty(property.Key, property.Value);
                if (safeProperty == null)
                {
                    logEvent.RemovePropertyIfPresent(property.Key);
                }
                else
                {
                    logEvent.AddOrUpdateProperty(safeProperty);
                }
            }

            logEvent.AddOrUpdateProperty(new LogEventProperty(Constants.SensitiveInformation, new StructureValue(sensitiveProperties.Values)));
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (_applicationId == null)
            {
                InitProperties(propertyFactory);
            }

            logEvent.AddPropertyIfAbsent(_applicationId);
            logEvent.AddPropertyIfAbsent(_applicationName);
            logEvent.AddPropertyIfAbsent(_applicationInstanceId);
            logEvent.AddPropertyIfAbsent(_applicationInstanceName);
            logEvent.AddPropertyIfAbsent(_applicationVersion);
            logEvent.AddPropertyIfAbsent(_machineName);

            if (logEvent.Properties.ContainsKey(COMPONENTKEY))
            {
                var sourceContext = logEvent.Properties[COMPONENTKEY];
                var idProp        = new LogEventProperty(ApplicationLoggingProperties.ApplicationComponentId, sourceContext);
                var nameProp      = new LogEventProperty(ApplicationLoggingProperties.ApplicationComponentName, sourceContext);
                logEvent.AddOrUpdateProperty(idProp);
                logEvent.AddOrUpdateProperty(nameProp);
            }

            var processIdProp = new LogEventProperty(ApplicationLoggingProperties.ProcessId, new ScalarValue(System.Diagnostics.Process.GetCurrentProcess().Id));
            var threadIdProp  = new LogEventProperty(ApplicationLoggingProperties.ThreadId, new ScalarValue(System.Environment.CurrentManagedThreadId));

            logEvent.AddOrUpdateProperty(processIdProp);
            logEvent.AddOrUpdateProperty(threadIdProp);
        }
Пример #4
0
        void _EnrichResponse(HttpResponse httpResponse, LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var headers = transformHeaders(httpResponse.Headers);

            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ResponseHeaders", headers));
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ResponseStatusCode", httpResponse.StatusCode));
        }
Пример #5
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(new LogEventProperty(nameof(errorLog.Duration), new ScalarValue(errorLog.Duration)));
     logEvent.AddOrUpdateProperty(new LogEventProperty(nameof(errorLog.StatusCode), new ScalarValue(errorLog.StatusCode)));
     logEvent.AddOrUpdateProperty(new LogEventProperty(nameof(errorLog.RequestId), new ScalarValue(errorLog.RequestId)));
     logEvent.AddOrUpdateProperty(new LogEventProperty(nameof(errorLog.ResolvedPath), new ScalarValue(errorLog.ResolvedPath)));
     logEvent.AddOrUpdateProperty(new LogEventProperty(nameof(errorLog.RequestedPath), new ScalarValue(errorLog.RequestedPath)));
 }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var correlationId     = CallContext.LogicalGetData("CorrelationId") as Guid?;
            var resultOfMessageId = CallContext.LogicalGetData("ResultOfMessageId") as Guid?;

            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("CorrelationId", correlationId));
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ResultOfMessageId", resultOfMessageId));
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ThreadId", Guid.Empty.ToString(), false));

            if (_userName != null)
            {
                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("UserName", _userName, false));
            }
        }
Пример #8
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var activity = Activity.Current;

            if (activity != null)
            {
                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("trace.id", activity.TraceId));
                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("span.id", activity.SpanId));
            }
        }
Пример #9
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var elapsed      = (DateTime.UtcNow - _timestamp).TotalMilliseconds;
            var elapsedTotal = (DateTime.UtcNow - _timestampStart).TotalMilliseconds;

            _timestamp = DateTime.UtcNow;
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ElapsedMs", elapsed));
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ElapsedMsTotal", elapsedTotal));
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("Profiler", _name));
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var tracer = GlobalTracer.Instance;

            if (tracer?.ActiveSpan == null)
            {
                return;
            }
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("TraceId", tracer.ActiveSpan.Context.TraceId));
            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("SpanId", tracer.ActiveSpan.Context.SpanId));
        }
Пример #11
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.RemovePropertyIfPresent("ActionId");
     logEvent.RemovePropertyIfPresent("ConnectionId");
     logEvent.RemovePropertyIfPresent("RequestId");
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(nameof(IOperationContext.SessionId), _operationContext.SessionId));
     if (_operationContext.Session != null)
     {
         logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(nameof(IOperationContext.Session.UserId), _operationContext.Session.UserId));
     }
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(nameof(IOperationContext.CorrelationId), _operationContext.CorrelationId.ToString()));
 }
Пример #12
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (!string.IsNullOrWhiteSpace(_serviceName))
            {
                logEvent.AddOrUpdateProperty(new LogEventProperty(LoggerFields.ServiceName, new ScalarValue(_serviceName)));
            }

            if (!string.IsNullOrWhiteSpace(_environment))
            {
                logEvent.AddOrUpdateProperty(new LogEventProperty(LoggerFields.Environment, new ScalarValue(_environment)));
            }
        }
Пример #13
0
        public override JObject Build(LogEvent logEvent)
        {
            Tuple <string, string> excMessageTuple = GetExceptionMessages(logEvent.Exception);
            string exceptionDetail = excMessageTuple.Item1;
            string stackTrace      = excMessageTuple.Item2;

            logEvent.AddOrUpdateProperty(new LogEventProperty("ExceptionSource", new ScalarValue(logEvent.Exception.Source)));
            logEvent.AddOrUpdateProperty(new LogEventProperty("ExceptionMessage", new ScalarValue(exceptionDetail)));
            logEvent.AddOrUpdateProperty(new LogEventProperty("StackTrace", new ScalarValue(stackTrace)));

            return(base.Build(logEvent));
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent.Exception == null)
            {
                return;
            }

            var type  = new LogEventProperty("ExceptionType", new ScalarValue(logEvent.Exception.GetType().Name));
            var value = propertyFactory.CreateProperty("EscapedException", logEvent.Exception.ToString().Replace("\r\n", "\\r\\n"));

            logEvent.AddOrUpdateProperty(type);
            logEvent.AddOrUpdateProperty(value);
        }
Пример #15
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (_contextAccessor.HttpContext == null)
            {
                return;
            }

            var correlationIdProperty =
                new LogEventProperty(CorrelationIdPropertyName, new ScalarValue(GetCorrelationId()));
            var userIdProperty = new LogEventProperty(UserIdPropertyName, new ScalarValue(GetUserId()));

            logEvent.AddOrUpdateProperty(correlationIdProperty);
            logEvent.AddOrUpdateProperty(userIdProperty);
        }
Пример #16
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            if (_httpContextAccessor?.HttpContext?.Request == null)
            {
                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(_claimProperty, "There is no HttpContext.Request yet!", true));
                return;
            }

            var user = _httpContextAccessor.HttpContext.User;

            if (user == null)// || !user.Identity.IsAuthenticated)
            {
                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(_claimProperty, "No user or user is not authenticated!", true));
                return;
            }

            var claims = new List <Claim>();

            claims.Add(new Claim("businessAccountId", Guid.NewGuid().ToString()));
            claims.Add(new Claim("userAccountId", Guid.NewGuid().ToString()));
            claims.Add(new Claim("email", "*****@*****.**"));

            //var claims = ((ClaimsIdentity)user.Identity).Claims.ToList();

            if (!claims.Any())
            {
                logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(_claimProperty, "No claims for user!", true));
            }

            var claimValue = GetClaimValueFromClaims(claims);

            if (_sanitizeLogOutput)
            {
                claimValue = GetSanitizedLogOutput(claimValue);
            }

            if (string.IsNullOrWhiteSpace(claimValue))
            {
                return;
            }

            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(_claimProperty, claimValue, true));
        }
Пример #17
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            SerilogScope scope = this;

            while (scope != null)
            {
                var properties = scope._state as IEnumerable <KeyValuePair <string, object> >;
                if (properties != null)
                {
                    foreach (var kv in properties)
                    {
                        if (kv.Key == SerilogLoggerAdapter.OriginalFormatPropertyName)
                        {
                            continue;
                        }
                        var key = kv.Key;
                        var destructureObject = false;
                        if (key.StartsWith("@"))
                        {
                            key = key.Substring(1);
                            destructureObject = true;
                        }
                        var property = propertyFactory.CreateProperty(key, kv.Value, destructureObject);
                        logEvent.AddPropertyIfAbsent(property);
                    }
                }

                scope = scope._parent;
            }

            logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("Scope", _scopesChain));
        }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (_executionContextAccessor.IsAvailable)
     {
         logEvent.AddOrUpdateProperty(new LogEventProperty("CorrelationId", new ScalarValue(_executionContextAccessor.CorrelationId)));
     }
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (silentLogs.Contains(logEvent.Exception?.Source))
     {
         logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("Silent", "SILENT-"));
     }
 }
Пример #20
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     foreach (var kvp in _properties)
     {
         logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(kvp.Key, kvp.Value, _destructureObjects));
     }
 }
Пример #21
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propFactory)
 {
     foreach ((string key, string value)prop in GetPropertiesAsRedacted(logEvent.Properties.ToArray()))
     {
         logEvent.AddOrUpdateProperty(propFactory.CreateProperty(prop.key, prop.value));
     }
 }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            var httpContext = HttpContext.Current;

            if (httpContext == null)
            {
                return;
            }

            var mvcInfo = httpContext.Items[Constants.MvcContextInfoKey] as IReadOnlyDictionary <MvcRequestInfoKey, object>;

            if (mvcInfo != null)
            {
                var propertyValue = mvcInfo[_infoItemKey];

                var logEventProperty = propertyFactory.CreateProperty(_logPropertyName, propertyValue, _destructureObjects);

                logEvent.AddOrUpdateProperty(logEventProperty);
            }
        }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (logEvent.Exception != null)
     {
         logEvent.AddOrUpdateProperty(new LogEventProperty("ExceptionMessage", new ScalarValue(ExceptionWithoutStackTrace(logEvent.Exception))));
     }
 }
Пример #24
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "ThreadId", Thread.CurrentThread.ManagedThreadId.ToString("D4")));
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(
                                      "ProcessId", _processId));
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     foreach (var prop in _props)
     {
         logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty(prop.Key, prop.Value));
     }
 }
Пример #26
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(new LogEventProperty(
                                      "Context",
                                      new ScalarValue($"Command: {_command.Id}")
                                      ));
 }
Пример #27
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var httpContext = _contextAccessor.HttpContext;

            if (httpContext == null)
            {
                return;
            }

            if (httpContext.Items[MyRequestIdItemKey] is LogEventProperty logEventProperty)
            {
                logEvent.AddPropertyIfAbsent(logEventProperty);
                return;
            }

            var header    = "my-request-id";
            var requestId = httpContext.Request.GetHeader(header);

            if (string.IsNullOrWhiteSpace(requestId))
            {
                requestId = Guid.NewGuid().ToString("N");
            }

            var property = new LogEventProperty(MyRequestIdPropertyName, new ScalarValue(requestId));

            httpContext.Items.Add(MyRequestIdItemKey, property);
            logEvent.AddOrUpdateProperty(property);
        }
Пример #28
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var value    = LogValueResolver.Resolve(this);
            var property = new LogEventProperty("RequestPath", new ScalarValue(value));

            logEvent.AddOrUpdateProperty(property);
        }
Пример #29
0
    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
    {
        var day      = _timeProvider.GetTime().DayOfWeek;
        var property = new LogEventProperty(PropertyName, new ScalarValue(day));

        logEvent.AddOrUpdateProperty(property);
    }
Пример #30
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (logEvent.Exception != null)
     {
         logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("ExceptionDetail", JsonConvert.SerializeObject(logEvent.Exception)));
     }
 }