本文整理匯總了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();
}