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