예제 #1
0
        /// <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);
        }
 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
 }
예제 #3
0
        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)));
            }
        }
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null) throw new ArgumentNullException("logEvent");
            if (propertyFactory == null) throw new ArgumentNullException("propertyFactory");

            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(
                propertyFactory.CreateProperty(HttpRequestPropertyName,
                new
                {
                    SessionId = sessionId,
                    Id = requestId,
                },
                destructureObjects: true));
        }
        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()));
        }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (logEvent.Exception != null)
     {
         logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ExceptionDetail", this.DestructureException(logEvent.Exception), true));
     }
 }
예제 #7
0
 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);
 }
예제 #8
0
        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"])));
        }
예제 #9
0
        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>
        /// 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);
        }
예제 #11
0
        /// <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);
            }
        }
예제 #12
0
 /// <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));
     }
 }
예제 #13
0
        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));
        }
예제 #14
0
        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 :(
            }
        }
예제 #15
0
 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);
             }
         }
     }
 }
예제 #16
0
        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));
        }
예제 #17
0
        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);
        }
예제 #18
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            string log4NetLevel;

            switch (logEvent.Level)
            {
            case LogEventLevel.Debug:
                log4NetLevel = "DEBUG";
                break;

            case LogEventLevel.Error:
                log4NetLevel = "ERROR";
                break;

            case LogEventLevel.Fatal:
                log4NetLevel = "FATAL";
                break;

            case LogEventLevel.Information:
                log4NetLevel = "INFO ";     //Padded string so that all log levels are 5 chars long (needed to keep the txt log file lined up nicely)
                break;

            case LogEventLevel.Verbose:
                log4NetLevel = "ALL  ";     //Padded string so that all log levels are 5 chars long (needed to keep the txt log file lined up nicely)
                break;

            case LogEventLevel.Warning:
                log4NetLevel = "WARN ";     //Padded string so that all log levels are 5 chars long (needed to keep the txt log file lined up nicely)
                break;

            default:
                log4NetLevel = string.Empty;
                break;
            }

            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Log4NetLevel", log4NetLevel));
        }
예제 #19
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory factory)
        {
            void _(String name, Object val, Boolean destructure = false)
            {
                logEvent.AddOrUpdateProperty(factory.CreateProperty(name, val, destructure));
            }

            var(user, message, guild, channel) = this.Context;
            _("Context.User.Id", user.Id);
            _("Context.User.Name", user.Username);
            _("Context.User.Discriminator", user.DiscriminatorValue);
            _("Context.User.Nickname", (user as IGuildUser)?.Nickname);

            _("Context.Message.Id", message.Id);
            _("Context.Message.Content", message.Content);

            _("Context.Guild.Id", guild?.Id);
            _("Context.Guild.Name", guild?.Name);

            _("Context.Channel.Id", channel.Id);
            _("Context.Channel.Name", channel.Name);

            if (channel is SocketTextChannel textChannel)
            {
                var categoryName = textChannel.Category.Name;
                _("Context.Channel.Category", categoryName);
                _("Context.Channel.IsNsfw", textChannel.IsNsfw);
            }

            if (!(this.Context is KuuhakuCommandContext kuuhakuContext))
            {
                return;
            }

            _("Context.Stopwatch.ElapsedMs", kuuhakuContext.Stopwatch.ElapsedMilliseconds);
            _("Context.Stopwatch.IsRunning", kuuhakuContext.Stopwatch.IsRunning);
        }
예제 #20
0
        /// <summary>
        /// Enrich LogEvent message with provided CorrelationId or generate a new one for this HTTP request.
        /// </summary>
        /// <param name="logEvent">Log Event</param>
        /// <param name="propertyFactory">Serilog Property Factory</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null)
            {
                throw new ArgumentNullException(nameof(logEvent));
            }

            if (propertyFactory == null)
            {
                throw new ArgumentNullException(nameof(propertyFactory));
            }

            if (string.IsNullOrWhiteSpace(_serviceName))
            {
                if (string.IsNullOrWhiteSpace(_serviceName))
                {
                    _serviceName = "N/A";
                }
            }

            LogEventProperty property = propertyFactory.CreateProperty(LoggingConstants.ServiceNamePropertiesName, _serviceName, false);

            logEvent.AddOrUpdateProperty(property);
        }
예제 #21
0
        /// <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>
            {
                this._cachedProperties.GetOrAdd("MachineName",
                                                k => propertyFactory.CreateProperty(k, Environment.MachineName)),
                this._cachedProperties.GetOrAdd("Is64BitOperatingSystem",
                                                k => propertyFactory.CreateProperty(k, RuntimeInformation.OSArchitecture == Architecture.X64 || RuntimeInformation.OSArchitecture == Architecture.Arm64)),
                this._cachedProperties.GetOrAdd("OSDescription", k => propertyFactory.CreateProperty(k, RuntimeInformation.OSDescription)),
                this._cachedProperties.GetOrAdd("ProcessorCount",
                                                k => propertyFactory.CreateProperty(k, Environment.ProcessorCount)),
                this._cachedProperties.GetOrAdd(".NETRuntime", k => propertyFactory.CreateProperty(k, PlatformServices.Default.Application.RuntimeFramework.FullName)),
                this._cachedProperties.GetOrAdd(".NETVersion", k => propertyFactory.CreateProperty(k, PlatformServices.Default.Application.RuntimeFramework.Version))
            };

            foreach (var p in properties)
            {
                logEvent.AddPropertyIfAbsent(p);
            }
        }
예제 #22
0
 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"));
 }
예제 #23
0
 /// <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);
 }
예제 #24
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AzureWebJobsName", Environment.GetEnvironmentVariable("WEBJOBS_NAME") ?? "NO_WEBJOB"));
 }
예제 #25
0
 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"));
 }
예제 #26
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "TestName", TestExecutionContext.TestName));
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(
         propertyFactory.CreateProperty("MessageTemplate", logEvent.MessageTemplate.Text)
         );
 }
 /// <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(ProcessNamePropertyName, System.Diagnostics.Process.GetCurrentProcess().ProcessName);
     logEvent.AddPropertyIfAbsent(_cachedProperty);
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(_propertyName, _correlationIdProvider.CorrelationId));
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("_CreatedDateTime", DateTimeOffset.UtcNow));
 }
예제 #31
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) =>
 logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                  "Severity", LogLevelSeverityMap[logEvent.Level]));
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(_keyValue.Key, _keyValue.Value));
 }
예제 #33
0
        private void AddLogEventProperties(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var currentCtx = new HttpContextWrapper(HttpContext.Current);
            var e          = logEvent.Exception;
            var ctx        = new HttpContextData(e, currentCtx, FilterSettings);

            if (e != null && IncludeExceptionInfo)
            {
                propertyFactory.CreateProperty("_" + nameof(ctx.ExceptionMessage), ctx.ExceptionMessage).AddIfAbsent(logEvent);
                propertyFactory.CreateProperty("_" + nameof(ctx.ExceptionDetail), ctx.ExceptionDetail).AddIfAbsent(logEvent);
                propertyFactory.CreateProperty("_" + nameof(ctx.ExceptionSource), ctx.ExceptionSource).AddIfAbsent(logEvent);
                propertyFactory.CreateProperty("_" + nameof(ctx.ExceptionType), ctx.ExceptionType).AddIfAbsent(logEvent);
            }

            propertyFactory.CreateProperty("_" + nameof(ctx.Host), ctx.Host).AddIfAbsent(logEvent);
            propertyFactory.CreateProperty("_" + nameof(ctx.HTTPMethod), ctx.HTTPMethod).AddIfAbsent(logEvent);
            propertyFactory.CreateProperty("_" + nameof(ctx.IPAddress), ctx.IPAddress).AddIfAbsent(logEvent);
            propertyFactory.CreateProperty("_" + nameof(ctx.Url), ctx.Url).AddIfAbsent(logEvent);
            propertyFactory.CreateProperty("_" + nameof(ctx.StatusCode), ctx.StatusCode).AddIfAbsent(logEvent);

            var kvps = ctx.CustomData;

            if (kvps != null)
            {
                foreach (var v in kvps)
                {
                    propertyFactory.CreateProperty("cd: " + v.Key, v.Value).AddIfAbsent(logEvent);
                }
            }

            var sv = ctx.ServerVariablesSerializable;

            foreach (var v in sv)
            {
                propertyFactory.CreateProperty("sv: " + v.Name, v.Value).AddIfAbsent(logEvent);
            }

            sv = ctx.RequestHeadersSerializable;
            foreach (var v in sv)
            {
                propertyFactory.CreateProperty("rh: " + v.Name, v.Value).AddIfAbsent(logEvent);
            }

            sv = ctx.FormSerializable;
            foreach (var v in sv)
            {
                propertyFactory.CreateProperty("fm: " + v.Name, v.Value).AddIfAbsent(logEvent);
            }

            sv = ctx.QueryStringSerializable;
            foreach (var v in sv)
            {
                propertyFactory.CreateProperty("qs: " + v.Name, v.Value).AddIfAbsent(logEvent);
            }

            sv = ctx.CookiesSerializable;
            foreach (var v in sv)
            {
                propertyFactory.CreateProperty("cookie: " + v.Name, v.Value).AddIfAbsent(logEvent);
            }
        }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ActivityId", Activity.Current?.Id));
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ParentActivityId", Activity.Current?.ParentId));
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ActivityRootId", Activity.Current?.RootId));
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     var environmentVariable = this.GetType().Assembly.GetName().Version;
     _cachedProperty = _cachedProperty ?? propertyFactory.CreateProperty(AssemblyVersionPropertyName, environmentVariable);
     logEvent.AddPropertyIfAbsent(_cachedProperty);
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(_propertyName, _source.FullyQualifiedName));
 }
예제 #37
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", Thread.CurrentThread.ManagedThreadId));
 }
예제 #38
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            string id = Thread.CurrentThread.Name ?? Thread.CurrentThread.ManagedThreadId.ToString();

            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", id));
        }
예제 #39
0
 /// <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(EnvironmentUserNamePropertyName, GetEnvironmentUserName());
     logEvent.AddPropertyIfAbsent(_cachedProperty);
 }
예제 #41
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("X-Real-IP", this.ctx.GetRemoteIp()));
 }
예제 #42
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     var property = propertyFactory.CreateProperty("Correlation", Correlation);
     logEvent.AddPropertyIfAbsent(property);
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("EVN", evnName.Value));
 }
        /// <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(Ec2InstanceIdPropertyName, Ec2InstanceMetadata.GetProperty("/instance-id"));

            logEvent.AddPropertyIfAbsent(_cachedProperty);
        }
예제 #45
0
 /// <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, ILogEventPropertyFactory propertyFactory)
        {
            var ctx = _context;

            if (ctx.Items.TryGetValue("RequestId", out var requestId))
            {
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("RequestId", requestId as string));
            }
            if (ctx.Items.TryGetValue("Hostname", out var hostname))
            {
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Hostname", hostname as string));
            }

            object auth_user;

            if (ctx.Items.TryGetValue("auth_user", out auth_user))
            {
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                 "UserId", auth_user as string));
            }

            if (ctx.Response != null)
            {
                object start;
                if (ctx.Response != null && ctx.Items.TryGetValue("StartTicks", out start))
                {
                    var elapsed = (DateTime.UtcNow.Ticks - (long)start) / TimeSpan.TicksPerMillisecond;
                    logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                     "ElapsedTime", elapsed.ToString()));

                    using (var stream = new MemoryStream())
                    {
                        ctx.Response.Contents.Invoke(stream);
                        try
                        {
                            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                             "ResponseContentLength", stream.Length));
                        }
                        catch (ObjectDisposedException)
                        {
                            // skip logging content length if stream is prematurely closed
                            // seems to happen a lot when debugging
                        }
                    }

                    logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                     "ResponseContentType", ctx.Response.ContentType));
                }
            }
            else
            {
                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                 "UserHostAddress", GetUserIpAddress()));

                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                 "RequestContentLength", ctx.Request.Headers.ContentLength));

                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                 "RequestContentType", ctx.Request.Headers.ContentType));

                logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                                 "Host", ctx.Request.Headers.Host));
            }
        }
예제 #47
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("Exception", logEvent.Exception.Demystify()));
 }
예제 #48
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(
         propertyFactory.CreateProperty(PropertyName, this.contextAccessor.HttpContext?.TraceIdentifier ?? "-"));
 }
예제 #49
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Component", "global"));
 }
예제 #50
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(FunctionsTrace.EventId, -1));
 }
예제 #51
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Component", "global"));
 }
예제 #52
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "Service", _serviceName));
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Username", _user.Username));
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ComputerName", _user.Lab));
 }
예제 #54
0
 private void AddProperty(LogEvent logEvent, ILogEventPropertyFactory propertyFactory, string name, object val)
 => logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(name, val));
예제 #55
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("LevelValue", (int)logEvent.Level, false));
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("MachineName", Environment.MachineName));
 }
예제 #56
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(
         propertyFactory.CreateProperty(_keyValue.Key, JsonConvert.SerializeObject(_keyValue.Value)));
 }
 /// <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(EnvironmentUserNamePropertyName, GetEnvironmentUserName());
     logEvent.AddPropertyIfAbsent(_cachedProperty);
 }
예제 #58
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("MachineName", Environment.MachineName));
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AppDomainName", AppDomain.CurrentDomain.FriendlyName));
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ProcessName", Process.GetCurrentProcess().ProcessName));
 }
예제 #59
0
 /// <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.AddOrUpdateProperty(propertyFactory.CreateProperty("InstanceId", RoleEnvironment.CurrentRoleInstance.Id));
 }