本文整理汇总了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());
}
示例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();
}
}
示例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());
}
示例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());
}
示例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));
}