本文整理汇总了C#中log4net.Layout.PatternLayout.AddConverter方法的典型用法代码示例。如果您正苦于以下问题:C# PatternLayout.AddConverter方法的具体用法?C# PatternLayout.AddConverter怎么用?C# PatternLayout.AddConverter使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类log4net.Layout.PatternLayout
的用法示例。
在下文中一共展示了PatternLayout.AddConverter方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: addConveters
private void addConveters(PatternLayout patternLayout)
{
foreach (ConverterInfo conveterInfo in m_converters)
{
patternLayout.AddConverter(conveterInfo);
}
}
示例2: OnLoad
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
var patternLayout = new PatternLayout();
patternLayout.AddConverter("rfc3339", typeof(Rfc3339Converter));
patternLayout.ConversionPattern = "%rfc3339 %level %message%newline";
patternLayout.ActivateOptions();
var a = new TextboxAppender(this.textBoxProgress)
{
Layout = patternLayout,
Threshold = Level.Debug,
Name = textBoxProgress.Name,
};
a.ActivateOptions();
appender = a;
((Hierarchy)log4net.LogManager.GetRepository()).Root.AddAppender(appender);
}
示例3: TestAddingCustomPattern
[Test] public void TestAddingCustomPattern()
{
StringAppender stringAppender = new StringAppender();
PatternLayout layout = new PatternLayout();
layout.AddConverter("TestAddingCustomPattern", typeof(TestMessagePatternConverter));
layout.ConversionPattern = "%TestAddingCustomPattern";
layout.ActivateOptions();
stringAppender.Layout = layout;
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
ILog log1 = LogManager.GetLogger(rep.Name, "TestAddingCustomPattern");
log1.Info("TestMessage");
Assert.AreEqual("TestMessage", stringAppender.GetString(), "%TestAddingCustomPattern not registered");
stringAppender.Reset();
}
示例4: NamedPatternConverterWithPrecision2ShouldStripLessLeadingStuffIfPresent
public void NamedPatternConverterWithPrecision2ShouldStripLessLeadingStuffIfPresent() {
StringAppender stringAppender = new StringAppender();
PatternLayout layout = new PatternLayout();
layout.AddConverter("message-as-name", typeof(MessageAsNamePatternConverter));
layout.ConversionPattern = "%message-as-name{2}";
layout.ActivateOptions();
stringAppender.Layout = layout;
ILoggerRepository rep = LogManager.CreateRepository(Guid.NewGuid().ToString());
BasicConfigurator.Configure(rep, stringAppender);
ILog log1 = LogManager.GetLogger(rep.Name, "TestAddingCustomPattern");
log1.Info("NoDots");
Assert.AreEqual("NoDots", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
log1.Info("One.Dot");
Assert.AreEqual("One.Dot", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
log1.Info("Tw.o.Dots");
Assert.AreEqual("o.Dots", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
log1.Info("TrailingDot.");
Assert.AreEqual("TrailingDot.", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
log1.Info(".LeadingDot");
Assert.AreEqual("LeadingDot", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
// empty string and other evil combinations as tests for of-by-one mistakes in index calculations
log1.Info(string.Empty);
Assert.AreEqual(string.Empty, stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
log1.Info("x");
Assert.AreEqual("x", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
log1.Info(".");
Assert.AreEqual(".", stringAppender.GetString(), "%message-as-name not registered");
stringAppender.Reset();
}