當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。