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


C# LoggerConfiguration.Information方法代码示例

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


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

示例1: LoggingLevelSwitchDynamicallyChangesLevel

        public void LoggingLevelSwitchDynamicallyChangesLevel()
        {
            var events = new List<LogEvent>();
            var sink = new DelegatingSink(events.Add);

            var levelSwitch = new LoggingLevelSwitch(LogEventLevel.Information);

            var log = new LoggerConfiguration()
                .MinimumLevel.ControlledBy(levelSwitch)
                .WriteTo.Sink(sink)
                .CreateLogger()
                .ForContext<LoggerTests>();

            log.Debug("Suppressed");
            log.Information("Emitted");
            log.Warning("Emitted");

            // Change the level
            levelSwitch.MinimumLevel = LogEventLevel.Error;

            log.Warning("Suppressed");
            log.Error("Emitted");
            log.Fatal("Emitted");

            Assert.Equal(4, events.Count);
            Assert.True(events.All(evt => evt.RenderMessage() == "Emitted"));
        }
开发者ID:serilog,项目名称:serilog,代码行数:27,代码来源:LoggerTests.cs

示例2: EventsCanBeExcludedByPredicate

        public void EventsCanBeExcludedByPredicate()
        {
            var seen = 0;

            var log = new LoggerConfiguration()
                .Filter.ByExcluding(Matching.WithProperty<int>("Count", p => p < 10))
                .WriteTo.Sink(new DelegatingSink(e => seen++))
                .CreateLogger();

            log.Warning("Unrelated");
            log.Information("{Count}", 5);
            log.Information("{Count}", "wrong type");
            log.Information("{Count}", 15);

            Assert.Equal(3, seen);
        }
开发者ID:serilog,项目名称:serilog,代码行数:16,代码来源:MatchingTests.cs

示例3: AttributesAreConsultedWhenDestructuring

        public void AttributesAreConsultedWhenDestructuring()
        {
            LogEvent evt = null;

            var log = new LoggerConfiguration()
                .Destructure.UsingAttributes()
                .WriteTo.Sink(new DelegatingSink(e => evt = e))
                .CreateLogger();

            var customized = new Customized
            {
                ImmutableScalar = new ImmutableScalar(),
                MutableScalar = new MutableScalar(),
                NotAScalar = new NotAScalar(),
                Ignored = "Hello, there",
                ScalarAnyway = new NotAScalar()
            };

            log.Information("Here is {@Customized}", customized);

            var sv = (StructureValue)evt.Properties["Customized"];
            var props = sv.Properties.ToDictionary(p => p.Name, p => p.Value);

            Assert.IsInstanceOf<ImmutableScalar>(props["ImmutableScalar"].LiteralValue());
            Assert.AreEqual(new MutableScalar().ToString(), props["MutableScalar"].LiteralValue());
            Assert.IsInstanceOf<StructureValue>(props["NotAScalar"]);
            Assert.IsFalse(props.ContainsKey("Ignored"));
            Assert.IsInstanceOf<NotAScalar>(props["ScalarAnyway"].LiteralValue());
        }
开发者ID:BugBusted,项目名称:serilog,代码行数:29,代码来源:AttributedDestructuringTests.cs

示例4: UsingSuperLongLogMessageWorks

        public void UsingSuperLongLogMessageWorks()
        {
            var charcounts = new[]
            {
                10*1000,
                20*1000,
                30*1000,
                40*1000,
                70*1000
            };
            foreach (var charcount in charcounts)
            {
                var log = new LoggerConfiguration()
                    .WriteTo.EventLog("EventLogSinkTests")
                    .CreateLogger();

                var guid = Guid.NewGuid().ToString("D");
                log.Information("This is a super long message which might be trimmed. Guid is {Guid}.The following text has {charcount} chars: {LongText}"
                    , guid
                    , charcount
                    , new string('x', charcount));

                Assert.IsTrue(EventLogMessageWithSpecificBodyExists(guid), "The message was not found in the eventlog. Charcount was " + charcount);
            }
        }
开发者ID:modulexcite,项目名称:serilog-sinks-eventlog,代码行数:25,代码来源:EventLogSinkTests.cs

示例5: WhenALoggerWritesToTheSinkItIsRetrievableFromTheTableWithProperties

		public void WhenALoggerWritesToTheSinkItIsRetrievableFromTheTableWithProperties()
		{
			var storageAccount = CloudStorageAccount.DevelopmentStorageAccount;
			var tableClient = storageAccount.CreateCloudTableClient();
			var table = tableClient.GetTableReference("LogEventEntity");

			table.DeleteIfExists();

			var logger = new LoggerConfiguration()
				.WriteTo.AzureTableStorageWithProperties(storageAccount)
				.CreateLogger();

			var exception = new ArgumentException("Some exception");

			const string messageTemplate = "{Properties} should go in their {Numbered} {Space}";

			logger.Information(exception, messageTemplate, "Properties", 1234, ' ');

			var result = table.ExecuteQuery(new TableQuery().Take(1)).First();
			
			// Check the presence of same properties as in previous version
			Assert.AreEqual(messageTemplate, result.Properties["MessageTemplate"].StringValue);
			Assert.AreEqual("Information", result.Properties["Level"].StringValue);
			Assert.AreEqual("System.ArgumentException: Some exception", result.Properties["Exception"].StringValue);
			Assert.AreEqual("\"Properties\" should go in their 1234  ", result.Properties["RenderedMessage"].StringValue);

			// Check the presence of the new properties.
			Assert.AreEqual("Properties", result.Properties["Properties"].PropertyAsObject);
			Assert.AreEqual(1234, result.Properties["Numbered"].PropertyAsObject);
			Assert.AreEqual(" ", result.Properties["Space"].PropertyAsObject);
		}
开发者ID:Sensarg22,项目名称:serilog-sinks-azuretablestorage,代码行数:31,代码来源:AzureTableStorageWithPropertiesSinkTests.cs

示例6: LoggerTest

        public void LoggerTest()
        {
            var logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.WebRequest(new Uri(Url))
                .CreateLogger();

            logger.Information("Hello World");
        }
开发者ID:WillemRB,项目名称:serilog-sinks-webrequest,代码行数:9,代码来源:WebRequestSinkTests.cs

示例7: UsingSpecialCharsWorks

        public void UsingSpecialCharsWorks()
        {
            var log = new LoggerConfiguration()
                .WriteTo.EventLog("EventLogSinkTests")
                .CreateLogger();

            var guid = Guid.NewGuid().ToString("D");
            log.Information("This is a mesage with a {Guid} and a special char {char}", guid, "%1");

            Assert.IsTrue(EventLogMessageWithSpecificBodyExists(guid), "The message was not found in the eventlog.");
        }
开发者ID:modulexcite,项目名称:serilog-sinks-eventlog,代码行数:11,代码来源:EventLogSinkTests.cs

示例8: Main

 static void Main()
 {
     const int iterations = 1000000;
     var log = new LoggerConfiguration()
         .WriteTo.File("test-" + Guid.NewGuid() + ".log")
         .CreateLogger();
     for (var i = 0; i < iterations; i++)
     {
         log.Information("Running iteration {I:00.0} for {@J}!", i, new { Goal = "Speed" });
     }
 }
开发者ID:DmitryNaumov,项目名称:serilog,代码行数:11,代码来源:Program.cs

示例9: UsingAngleBracketsInSourceWorks

        public void UsingAngleBracketsInSourceWorks()
        {
            var log = new LoggerConfiguration()
                .WriteTo.EventLog("EventLogSink<Tests>")
                .CreateLogger();

            var guid = Guid.NewGuid().ToString("D");
            log.Information("This is a normal mesage with a {Guid}", guid);

            Assert.IsTrue(EventLogMessageWithSpecificBodyExists(guid),
                "The message was not found in the eventlog.");
        }
开发者ID:modulexcite,项目名称:serilog-sinks-eventlog,代码行数:12,代码来源:EventLogSinkTests.cs

示例10: EnvironmentUserNameEnricherIsApplied

        public void EnvironmentUserNameEnricherIsApplied()
        {
            LogEvent evt = null;
            var log = new LoggerConfiguration()
                .Enrich.WithEnvironmentUserName()
                .WriteTo.Sink(new DelegatingSink(e => evt = e))
                .CreateLogger();

            log.Information(@"Has an EnvironmentUserName property with [domain\]userName");

            Assert.IsNotNull(evt);
            Assert.IsNotNullOrEmpty((string)evt.Properties["EnvironmentUserName"].LiteralValue());
        }
开发者ID:DmitryNaumov,项目名称:serilog,代码行数:13,代码来源:EnvironmentUserNameEnricherTests.cs

示例11: EventsAreWrittenToTheTextWriter

        public void EventsAreWrittenToTheTextWriter()
        {
            var sw = new StringWriter();

            var log = new LoggerConfiguration()
                .WriteTo.TextWriter(sw)
                .CreateLogger();

            var mt = Some.String();
            log.Information(mt);

            var s = sw.ToString();
            Assert.That(s.Contains(mt));
        }
开发者ID:DmitryNaumov,项目名称:serilog,代码行数:14,代码来源:TextWriterSinkTests.cs

示例12: AnExceptionThrownByAnEnricherIsNotPropagated

        public void AnExceptionThrownByAnEnricherIsNotPropagated()
        {
            var thrown = false;

            var l = new LoggerConfiguration()
                .Enrich.With(new DelegatingEnricher((le, pf) => {
                    thrown = true;
                    throw new Exception("No go, pal."); }))
                .CreateLogger();

            l.Information(Some.String());

            Assert.IsTrue(thrown);
        }
开发者ID:RossMerr,项目名称:serilog,代码行数:14,代码来源:LoggerTests.cs

示例13: AdditionalHeadersTest

        public void AdditionalHeadersTest()
        {
            var headers = new NameValueCollection();
            headers.Add("X-Test-Header", "Test Header Value");

            var logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .WriteTo.WebRequest(new Uri(glipWebhook), contentType: "application/json", headers: headers)
                .CreateLogger();

            var message = new GlipMessage();

            logger.Information("{{ \"icon\": {icon}, \"activity\": {activity}, \"title\": {title}, \"body\": {body} }}",
                message.Icon, message.Activity, message.Title, message.Body);
        }
开发者ID:WillemRB,项目名称:serilog-sinks-webrequest,代码行数:15,代码来源:WebRequestSinkTests.cs

示例14: EventsAreWrittenToTheTextWriterUsingFormatProvider

        public void EventsAreWrittenToTheTextWriterUsingFormatProvider()
        {
            var sw = new StringWriter();

            var french = CultureInfo.GetCultureInfo("fr-FR");
            var log = new LoggerConfiguration()
                .WriteTo.TextWriter(sw, formatProvider: french)
                .CreateLogger();

            var mt = String.Format(french, "{0}", 12.345);
            log.Information("{0}", 12.345);

            var s = sw.ToString();
            Assert.That(s.Contains(mt));
        }
开发者ID:DmitryNaumov,项目名称:serilog,代码行数:15,代码来源:TextWriterSinkTests.cs

示例15: SpecifyingThatATypeIsScalarCausesItToBeLoggedAsScalarEvenWhenDestructuring

        public void SpecifyingThatATypeIsScalarCausesItToBeLoggedAsScalarEvenWhenDestructuring()
        {
            var events = new List<LogEvent>();
            var sink = new DelegatingSink(events.Add);
            
            var logger = new LoggerConfiguration()
                .WriteTo.Sink(sink)
                .Destructure.AsScalar(typeof(AB))
                .CreateLogger();

            logger.Information("{@AB}", new AB());

            var ev = events.Single();
            var prop = ev.Properties["AB"];
            Assert.IsInstanceOf<ScalarValue>(prop);
        }
开发者ID:BugBusted,项目名称:serilog,代码行数:16,代码来源:LoggerConfigurationTests.cs


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