Exemplo n.º 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
 }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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);
 }
Exemplo n.º 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"])));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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));
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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 :(
            }
        }
Exemplo n.º 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);
             }
         }
     }
 }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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));
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 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"));
 }
Exemplo n.º 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);
 }
Exemplo n.º 24
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("AzureWebJobsName", Environment.GetEnvironmentVariable("WEBJOBS_NAME") ?? "NO_WEBJOB"));
 }
Exemplo n.º 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"));
 }
Exemplo n.º 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));
 }
Exemplo n.º 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));
 }
Exemplo n.º 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);
            }
        }
Exemplo n.º 34
0
 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));
 }
Exemplo n.º 35
0
 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));
 }
Exemplo n.º 37
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", Thread.CurrentThread.ManagedThreadId));
 }
Exemplo n.º 38
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            string id = Thread.CurrentThread.Name ?? Thread.CurrentThread.ManagedThreadId.ToString();

            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", id));
        }
Exemplo n.º 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);
 }
Exemplo n.º 41
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("X-Real-IP", this.ctx.GetRemoteIp()));
 }
Exemplo n.º 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);
        }
Exemplo n.º 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));
            }
        }
Exemplo n.º 47
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("Exception", logEvent.Exception.Demystify()));
 }
Exemplo n.º 48
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(
         propertyFactory.CreateProperty(PropertyName, this.contextAccessor.HttpContext?.TraceIdentifier ?? "-"));
 }
Exemplo n.º 49
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Component", "global"));
 }
Exemplo n.º 50
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(FunctionsTrace.EventId, -1));
 }
Exemplo n.º 51
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Component", "global"));
 }
Exemplo n.º 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));
 }
Exemplo n.º 54
0
 private void AddProperty(LogEvent logEvent, ILogEventPropertyFactory propertyFactory, string name, object val)
 => logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(name, val));
Exemplo n.º 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));
 }
Exemplo n.º 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);
 }
Exemplo n.º 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));
 }
Exemplo n.º 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));
 }