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


C# PatternLayout.Format方法代码示例

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


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

示例1: SimpleTest

		public void SimpleTest()
		{
			container.AddComponent("component1", typeof(SimpleLoggingComponent));
			SimpleLoggingComponent test = container["component1"] as SimpleLoggingComponent;

			test.DoSomething();

			String expectedLogOutput = String.Format("[INFO ] [{0}] - Hello world" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
			MemoryAppender memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
			TextWriter actualLogOutput = new StringWriter();
			PatternLayout patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");
			patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[0]);

			Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());

			container.AddComponent("component2", typeof(SmtpServer));
			ISmtpServer smtpServer = container["component2"] as ISmtpServer;

			smtpServer.Start();
			smtpServer.InternalSend("[email protected]", "[email protected]", "We're looking for a few good porgrammars.");
			smtpServer.Stop();

			expectedLogOutput = String.Format("[DEBUG] [Castle.Facilities.Logging.Tests.Classes.SmtpServer] - Stopped" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
			memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
			actualLogOutput = new StringWriter();
			patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");

			Assert.AreEqual(memoryAppender.GetEvents().Length, 4);

			patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[3]);

			Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:33,代码来源:ExtendedLog4NetFacilityTests.cs

示例2: Page_Load

    protected void Page_Load(object sender, EventArgs e)
    {
        // gather log4net output with small hack to get results...
        ILoggerRepository repository = LogManager.GetRepository();
        IAppender[] appenders = repository.GetAppenders();
        MemoryAppender appender = null;
        foreach (IAppender a in appenders)
        {
            if (a is MemoryAppender)
            {
                // we found our appender to look results from
                appender = a as MemoryAppender;
                break;
            }
        }

        if (appender != null)
        {
            appender.Clear();
            fulfillmentService.ProcessCustomer(customerEditController.CurrentCustomer.Id);
            LoggingEvent[] events = appender.GetEvents();
            StringWriter stringWriter = new StringWriter();
            PatternLayout layout = new PatternLayout("%date{HH:mm:ss} %-5level %logger{1}: %message<br />");
            foreach (LoggingEvent loggingEvent in events)
            {
                layout.Format(stringWriter, loggingEvent);
            }

            results.Text = stringWriter.ToString();
        }

    }
开发者ID:ouyangyl,项目名称:MySpringNet,代码行数:32,代码来源:FulfillmentResult.aspx.cs

示例3: SimpleTest

		public void SimpleTest()
		{
			container.Register(Component.For(typeof(SimpleLoggingComponent)).Named("component"));
			SimpleLoggingComponent test = container.Resolve<SimpleLoggingComponent>("component");

			test.DoSomething();

			String expectedLogOutput = String.Format("[INFO ] [{0}] - Hello world" + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
			MemoryAppender memoryAppender = ((Hierarchy) LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
			TextWriter actualLogOutput = new StringWriter();
			PatternLayout patternLayout = new PatternLayout("[%-5level] [%logger] - %message%newline");
			patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[0]);

			Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());
		}
开发者ID:RookieX,项目名称:Windsor,代码行数:15,代码来源:Log4NetFacilityTests.cs

示例4: ContextTest

		public void ContextTest()
		{
			container.AddComponent("component1", typeof(ComplexLoggingComponent));
			ComplexLoggingComponent complexLoggingComponent = container["component1"] as ComplexLoggingComponent;

			complexLoggingComponent.DoSomeContextual();

			String expectedLogOutput = String.Format("[DEBUG] [Castle.Facilities.Logging.Tests.Classes.ComplexLoggingComponent] [Outside Inside0] [bar] [flam] - Bim, bam boom." + Environment.NewLine, typeof(SimpleLoggingComponent).FullName);
			MemoryAppender memoryAppender = ((Hierarchy)LogManager.GetRepository()).Root.GetAppender("memory") as MemoryAppender;
			TextWriter actualLogOutput = new StringWriter();
			PatternLayout patternLayout = new PatternLayout("[%-5level] [%logger] [%properties{NDC}] [%properties{foo}] [%properties{flim}] - %message%newline");
			patternLayout.Format(actualLogOutput, memoryAppender.GetEvents()[0]);

			Assert.AreEqual(expectedLogOutput, actualLogOutput.ToString());
		}
开发者ID:AGiorgetti,项目名称:Castle.InversionOfControl,代码行数:15,代码来源:ExtendedLog4NetFacilityTests.cs

示例5: Test

        public void Test()
        {
            var layout = new PatternLayout("%date [%thread] %-5level %logger - %message%newline");

            var stringWriter = new StringWriter();
            layout.Format(stringWriter, new LoggingEvent(new LoggingEventData
                                                             {
                                                                 Level = Level.Error,
                                                                 Domain = "Domain",
                                                                 Message = "msg",
                                                                 ThreadName = "thread",
                                                                 LoggerName = "logger",
                                                                 TimeStamp = new DateTime(2001, 1, 1)
                                                             }));
            stringWriter.Flush();
            Assert.That(stringWriter.ToString(), Is.EqualTo("2001-01-01 00:00:00,000 [thread] ERROR logger - msg" + Environment.NewLine));
        }
开发者ID:Lundalogik,项目名称:log4net-logviewer,代码行数:17,代码来源:Log4NetTests.cs


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