当前位置: 首页>>代码示例>>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;未经允许,请勿转载。