当前位置: 首页>>代码示例>>C#>>正文


C# LogEvent.AddPropertyIfAbsent方法代码示例

本文整理汇总了C#中Serilog.Events.LogEvent.AddPropertyIfAbsent方法的典型用法代码示例。如果您正苦于以下问题:C# LogEvent.AddPropertyIfAbsent方法的具体用法?C# LogEvent.AddPropertyIfAbsent怎么用?C# LogEvent.AddPropertyIfAbsent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Serilog.Events.LogEvent的用法示例。


在下文中一共展示了LogEvent.AddPropertyIfAbsent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: Enrich

 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
 }
开发者ID:avodovnik,项目名称:MonitoringApplications,代码行数:9,代码来源:TenantEnricher.cs

示例2: Enrich

 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     if (logEvent.Exception != null)
     {
         logEvent.AddPropertyIfAbsent(propertyFactory.CreateProperty("ExceptionDetail", this.DestructureException(logEvent.Exception), true));
     }
 }
开发者ID:Rurouni,项目名称:MassiveOnlineUniversalServerEngine,代码行数:7,代码来源:ExceptionEnricher.cs

示例3: Enrich

 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);
 }
开发者ID:RossMerr,项目名称:serilog,代码行数:7,代码来源:LazyFixedPropertyEnricher.cs

示例4: Enrich

        public void Enrich(LogEvent logEvent)
        {
            if (logEvent == null) throw new ArgumentNullException("logEvent");

            if (HttpContext.Current == null)
                return;

            int requestId;
            var requestIdItem = HttpContext.Current.Items[RequestIdItemName];
            if (requestIdItem == null)
                HttpContext.Current.Items[RequestIdItemName] = requestId = Interlocked.Increment(ref LastRequestId);
            else
                requestId = (int)requestIdItem;

            string sessionId = null;
            if (HttpContext.Current.Session != null)
                sessionId = HttpContext.Current.Session.SessionID;

            logEvent.AddPropertyIfAbsent(
                LogEventProperty.For(HttpRequestPropertyName,
                new
                {
                    SessionId = sessionId,
                    Id = requestId,
                },
                destructureObjects: true));
        }
开发者ID:sandcastle,项目名称:serilog,代码行数:27,代码来源:HttpRequestLogEventEnricher.cs

示例5: Enrich

        /// <summary>
        /// Enrich the log event with the current ASP.NET user name, if User.Identity.IsAuthenticated is true.</summary>
        /// <param name="logEvent">The log event to enrich.</param>
        /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null) 
                throw new ArgumentNullException("logEvent");

            var userName = _noneUsername;

            if (HttpContext.Current != null)
            {
                var context = new HttpContextWrapper(HttpContext.Current);

                if (context.User != null)
                {
                    if (context.User.Identity == null || context.User.Identity.IsAuthenticated == false)
                    {
                        if (_anonymousUsername != null)
                            userName = _anonymousUsername;
                    }
                    else
                    {
                        userName = context.User.Identity.Name;
                    }
                }
            }

            if (userName == null) 
                return;

            var userNameProperty = new LogEventProperty(UserNamePropertyName, new ScalarValue(userName));
            logEvent.AddPropertyIfAbsent(userNameProperty);
        }
开发者ID:teyc,项目名称:classic,代码行数:35,代码来源:UserNameEnricher.cs

示例6: Enrich

        /// <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);
        }
开发者ID:DmitryNaumov,项目名称:serilog,代码行数:14,代码来源:MachineNameEnricher.cs

示例7: Enrich

        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));
        }
开发者ID:davidlai-msft,项目名称:SimpleWAWS,代码行数:9,代码来源:UserNameEnricher.cs

示例8: Enrich

        /// <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);
        }
开发者ID:CSClassroom,项目名称:CSClassroom,代码行数:22,代码来源:AsyncFriendlyStackTraceEnricher.cs

示例9: Enrich

 /// <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));
     }
 }
开发者ID:richiej84,项目名称:serilog,代码行数:16,代码来源:PropertyBagEnricher.cs

示例10: Enrich

        /// <summary>
        /// Enrich the log event with an id assigned to the currently-executing HTTP request, if any.
        /// </summary>
        /// <param name="logEvent">The log event to enrich.</param>
        /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null) throw new ArgumentNullException("logEvent");

            if (HttpContext.Current == null)
                return;

            var serviceProvider = (IServiceProvider)HttpContext.Current;
            var workerReqest = (HttpWorkerRequest)serviceProvider.GetService(typeof(HttpWorkerRequest));
            var requestId = workerReqest.RequestTraceIdentifier;

            var requestIdProperty = new LogEventProperty(HttpRequestTraceIdPropertyName, new ScalarValue(requestId));
            logEvent.AddPropertyIfAbsent(requestIdProperty);
        }
开发者ID:NikolaR,项目名称:serilog,代码行数:19,代码来源:HttpRequestTraceIdEnricher.cs

示例11: Enrich

        /// <summary>
        /// Enrich the log event.
        /// </summary>
        /// <param name="logEvent">The log event to enrich.</param>
        /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null) throw new ArgumentNullException("logEvent");

            if (HttpContextCurrent.Request == null)
                return;

            if (string.IsNullOrWhiteSpace(HttpContextCurrent.Request.UserHostName))
                return;
            
            var userHostName = HttpContextCurrent.Request.UserHostName;
            var httpRequestClientHostnameProperty = new LogEventProperty(HttpRequestClientHostNamePropertyName, new ScalarValue(userHostName));
            logEvent.AddPropertyIfAbsent(httpRequestClientHostnameProperty);
        }
开发者ID:teyc,项目名称:classic,代码行数:19,代码来源:HttpRequestClientHostNameEnricher.cs

示例12: Enrich

        /// <summary>
        /// Enrich the log event with the current ASP.NET session id, if sessions are enabled.</summary>
        /// <param name="logEvent">The log event to enrich.</param>
        /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null) throw new ArgumentNullException("logEvent");

            if (HttpContext.Current == null)
                return;

            if (HttpContext.Current.Session == null)
                return;

            var sessionId = HttpContext.Current.Session.SessionID;
            var sesionIdProperty = new LogEventProperty(HttpSessionIdPropertyName, new ScalarValue(sessionId));
            logEvent.AddPropertyIfAbsent(sesionIdProperty);
        }
开发者ID:RossMerr,项目名称:serilog,代码行数:18,代码来源:HttpSessionIdEnricher.cs

示例13: Enrich

 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);
             }
         }
     }
 }
开发者ID:njmube,项目名称:Logging,代码行数:15,代码来源:SerilogLoggerProvider.cs

示例14: Enrich

        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));
        }
开发者ID:davidlai-msft,项目名称:SimpleWAWS,代码行数:15,代码来源:ExperimentEnricher.cs

示例15: Enrich

        /// <summary>
        /// Enrich the log event.
        /// </summary>
        /// <param name="logEvent">The log event to enrich.</param>
        /// <param name="propertyFactory">Factory for creating new properties to add to the event.</param>
        public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
        {
            if (logEvent == null) throw new ArgumentNullException("logEvent");

            if (HttpContext.Current == null)
                return;

            if (HttpContextCurrent.Request == null)
                return;

            if (HttpContextCurrent.Request.UrlReferrer == null)
                return;

            var requestUrlReferrer = HttpContextCurrent.Request.UrlReferrer.ToString();
            var httpRequestUrlReferrerProperty = new LogEventProperty(HttpRequestUrlReferrerPropertyName, new ScalarValue(requestUrlReferrer));
            logEvent.AddPropertyIfAbsent(httpRequestUrlReferrerProperty);
        }
开发者ID:teyc,项目名称:classic,代码行数:22,代码来源:HttpRequestUrlReferrerEnricher.cs


注:本文中的Serilog.Events.LogEvent.AddPropertyIfAbsent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。