當前位置: 首頁>>代碼示例>>C#>>正文


C# LogEvent.AddOrUpdateProperty方法代碼示例

本文整理匯總了C#中Serilog.Events.LogEvent.AddOrUpdateProperty方法的典型用法代碼示例。如果您正苦於以下問題:C# LogEvent.AddOrUpdateProperty方法的具體用法?C# LogEvent.AddOrUpdateProperty怎麽用?C# LogEvent.AddOrUpdateProperty使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在Serilog.Events.LogEvent的用法示例。


在下文中一共展示了LogEvent.AddOrUpdateProperty方法的9個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: Enrich

        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)));
            }
        }
開發者ID:fenix2222,項目名稱:Nimbus,代碼行數:15,代碼來源:NimbusMessageEnricher.cs

示例2: Enrich

        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()));
        }
開發者ID:eoin55,項目名稱:HoneyBear.Spy,代碼行數:16,代碼來源:ClassAndMethodEnricher.cs

示例3: Enrich

        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"])));
        }
開發者ID:fenix2222,項目名稱:Nimbus,代碼行數:8,代碼來源:TestIdEnricher.cs

示例4: Enrich

        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));
        }
開發者ID:RichieYang,項目名稱:Rebus,代碼行數:13,代碼來源:RebusCorrelationIdEnricher.cs

示例5: Enrich

        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 :(
            }
        }
開發者ID:fenix2222,項目名稱:Nimbus,代碼行數:15,代碼來源:TestNameEnricher.cs

示例6: Enrich

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

            if (logEvent.Exception != null)
            {
                var exceptionType = logEvent.Exception.GetType();

                var nestedProperties = exceptionType.GetProperties().Select(
                    x => CreateLogProperty(x.Name, x.GetValue(logEvent.Exception, null))).ToList();
                nestedProperties.Add(CreateLogProperty("Type", exceptionType));

                logEvent.AddOrUpdateProperty(
                    new LogEventProperty(ExceptionPropertyName, new DictionaryValue(nestedProperties)));
            }
        }
開發者ID:object,項目名稱:VisualizeAllTheThings,代碼行數:17,代碼來源:StructuredExceptionEnricher.cs

示例7: Enrich

        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);
        }
開發者ID:jhonner72,項目名稱:plat,代碼行數:19,代碼來源:CallerEnricher.cs

示例8: Enrich

 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     logEvent.AddOrUpdateProperty(propertyFactory.CreateProperty("InstanceId", RoleEnvironment.CurrentRoleInstance.Id));
 }
開發者ID:Applicita,項目名稱:AzureWebFarm.OctopusDeploy,代碼行數:4,代碼來源:AzureEnvironment.cs

示例9: Enrich

 public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
 {
     var prop = propertyFactory.CreateProperty("User", _identity);
     logEvent.AddOrUpdateProperty(prop);
 }
開發者ID:InfiniteComputingSystems,項目名稱:Test,代碼行數:5,代碼來源:LoggingBootstrapper.cs


注:本文中的Serilog.Events.LogEvent.AddOrUpdateProperty方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。