Example #1
0
        /// <summary>
        /// Enriquecer el evento de registro.
        /// </summary>
        /// <param name="logEvent">El evento de registro para enriquecer.</param>
        /// <param name="propertyFactory">Fábrica para crear nuevas propiedades para agregar al evento.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var thread = Thread.CurrentThread;

            string threadValue = string.Empty;

            if (thread?.ManagedThreadId > 0)
            {
                threadValue = thread.ManagedThreadId.ToStringFormat();
            }

            if (!string.IsNullOrWhiteSpace(thread?.Name))
            {
                threadValue += thread?.ManagedThreadId > 0 ? $" - {thread.Name}" : thread?.Name;
            }

            var last = this.lastValue;

            if (last is null || (string)((ScalarValue)last.Value).Value != threadValue)
            {
                this.lastValue = last = new LogEventProperty(ThreadPropertyName, new ScalarValue(threadValue));

                logEvent?.AddPropertyIfAbsent(last);
            }
        }
Example #2
0
        /// <summary>
        /// Enriquecer el evento de registro.
        /// </summary>
        /// <param name="logEvent">El evento de registro para enriquecer.</param>
        /// <param name="propertyFactory">Fábrica para crear nuevas propiedades para agregar al evento.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var process = System.Diagnostics.Process.GetCurrentProcess();

            string processValue = string.Empty;

            if (process?.Id > 0)
            {
                processValue = process.Id.ToStringFormat();
            }

            if (!string.IsNullOrWhiteSpace(process?.ProcessName))
            {
                processValue += process?.Id > 0 ? $" - {process.ProcessName}" : process?.ProcessName;
            }

            var last = this.lastValue;

            if (last is null || (string)((ScalarValue)last.Value).Value != processValue)
            {
                this.lastValue = last = new LogEventProperty(ProcessPropertyName, new ScalarValue(processValue));

                logEvent?.AddPropertyIfAbsent(last);
            }
        }
        /// <summary>
        /// Enriquecer el evento de registro.
        /// </summary>
        /// <param name="logEvent">El evento de registro para enriquecer.</param>
        /// <param name="propertyFactory">Fábrica para crear nuevas propiedades para agregar al evento.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var last = this.lastValue;

            if (last is null || (string)((ScalarValue)last.Value).Value != this.title)
            {
                this.lastValue = last = new LogEventProperty(TitlePropertyName, new ScalarValue(this.title));

                logEvent?.AddPropertyIfAbsent(last);
            }
        }
Example #4
0
        /// <summary>
        /// Enriquecer el evento de registro.
        /// </summary>
        /// <param name="logEvent">El evento de registro para enriquecer.</param>
        /// <param name="propertyFactory">Fábrica para crear nuevas propiedades para agregar al evento.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var machineName = Environment.MachineName;

            var last = this.lastValue;

            if (last is null || (string)((ScalarValue)last.Value).Value != machineName)
            {
                this.lastValue = last = new LogEventProperty(MachineNamePropertyName, new ScalarValue(machineName));

                logEvent?.AddPropertyIfAbsent(last);
            }
        }
Example #5
0
    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
    {
        var exception = logEvent.Exception;

        if (exception is null)
        {
            return;
        }

        if (exception.TryReadData("Message type", out string messageType))
        {
            logEvent.AddPropertyIfAbsent(
                new("IncomingMessageType", new ScalarValue(messageType)));
        }

        if (exception.TryReadData("Message ID", out string incomingMessageId))
        {
            logEvent.AddPropertyIfAbsent(
                new("IncomingMessageId", new ScalarValue(incomingMessageId)));
        }

        if (exception.TryReadData("Transport message ID", out string incomingTransportMessageId))
        {
            logEvent.AddPropertyIfAbsent(
                new("IncomingTransportMessageId", new ScalarValue(incomingTransportMessageId)));
        }

        if (exception.TryReadData("Handler start time", out string handlerStartTime))
        {
            logEvent.AddPropertyIfAbsent(
                new("HandlerStartTime", new ScalarValue(DateTimeOffsetHelper.ToDateTimeOffset(handlerStartTime))));
        }

        if (exception.TryReadData("Handler failure time", out string handlerFailureTime))
        {
            logEvent.AddPropertyIfAbsent(
                new("HandlerFailureTime", new ScalarValue(DateTimeOffsetHelper.ToDateTimeOffset(handlerFailureTime))));
        }

        if (exception.TryReadData("Handler type", out string handlerType))
        {
            logEvent.AddPropertyIfAbsent(new("HandlerType", new ScalarValue(handlerType)));
        }

        if (exception.TryReadData("ExceptionLogState", out ExceptionLogState logState))
        {
            logEvent.AddPropertyIfAbsent(
                new("ProcessingEndpoint", new ScalarValue(logState.ProcessingEndpoint)));
            if (logState.CorrelationId is not null)
            {
                logEvent.AddPropertyIfAbsent(
                    new("CorrelationId", new ScalarValue(logState.CorrelationId)));
            }

            if (logState.ConversationId is not null)
            {
                logEvent.AddPropertyIfAbsent(
                    new("ConversationId", new ScalarValue(logState.ConversationId)));
            }

            if (logState.IncomingMessage is not null)
            {
                if (Log.BindProperty("IncomingMessage", logState.IncomingMessage, true, out var messageProperty))
                {
                    logEvent.AddPropertyIfAbsent(messageProperty);
                }
            }

            if (Log.BindProperty("IncomingHeaders", logState.IncomingHeaders, true, out var headersProperty))
            {
                logEvent.AddPropertyIfAbsent(headersProperty);
            }
        }
    }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("EVN", evnName.Value));
 }
Example #7
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("Component", "global"));
 }
Example #8
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));
 }
Example #9
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(new LogEventProperty(ActionNamePropertyName, new ScalarValue(new StackTrace().GetFrame(13).GetMethod().Name)));
 }
Example #10
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var property = new LogEventProperty("ServiceName", new ScalarValue(_serviceName.Value));

            logEvent.AddPropertyIfAbsent(property);
        }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(_keyValue.Key, _keyValue.Value));
 }
 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));
 }
Example #13
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory pf)
 {
     logEvent.AddPropertyIfAbsent(pf.CreateProperty("UtcTimestamp", logEvent.Timestamp.UtcDateTime));
 }
Example #14
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(EnvironmentUserNamePropertyName, GetEnvironmentUserName());
     logEvent.AddPropertyIfAbsent(_cachedProperty);
 }
Example #15
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "MachineName", System.Environment.MachineName));
 }
Example #16
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "Service", _serviceName));
 }
Example #17
0
 private void AddProperty(LogEvent logEvent, ILogEventPropertyFactory propertyFactory, string name, object val)
 => logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(name, val));
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("_CreatedDateTime", DateTimeOffset.UtcNow));
 }
Example #19
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(
         propertyFactory.CreateProperty(_keyValue.Key, JsonConvert.SerializeObject(_keyValue.Value)));
 }
Example #20
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);
 }
Example #21
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var property = new LogEventProperty("MessageId", new ScalarValue(_messageId));

            logEvent.AddPropertyIfAbsent(property);
        }
Example #22
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            string id = Thread.CurrentThread.Name ?? Thread.CurrentThread.ManagedThreadId.ToString();

            logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ThreadId", id));
        }
Example #23
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory) =>
 logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                  "Severity", LogLevelSeverityMap[logEvent.Level]));
        /// <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);
        }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "TestName", TestExecutionContext.TestName));
 }
        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));
            }
        }
Example #27
0
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty(
                                      "ThreadId", Thread.CurrentThread.ManagedThreadId));
 }
Example #28
0
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            var property = new LogEventProperty("LogType", new ScalarValue("Queue"));

            logEvent.AddPropertyIfAbsent(property);
        }
Example #29
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"));
 }
 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddPropertyIfAbsent(_property);
 }