1

現在、Common.Logging と log4net を使用しています。カスタムアペンダーを実装しました。

以下のコードで指定されているレイアウトをログに追加しようとしています。しかしRenderLoggingEvent(loggingEvent)、カスタムアペンダーで関数を出力すると、メッセージのみが表示されます (ただし、タイムスタンプは表示されません...)。

// create properties
// EXTERNAL expects log4net being configured somewhere else in
// your code and does nothing.
NameValueCollection properties = new NameValueCollection();
properties["configType"] = "EXTERNAL";

// set Adapter
Common.Logging.LogManager.Adapter = 
    new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(properties);

// create an object of the custom appender
var appender = new SimpleAppender();
appender.Name = "SimpleAppender";

// add layout to the appender
var layout = new log4net.Layout.PatternLayout()
{
    ConversionPattern = 
        "%date [%thread] %-5level %logger %ndc - %message%newline"
};
appender.Layout = layout;

//Let log4net configure itself based on the values provided
appender.ActivateOptions();
log4net.Config.BasicConfigurator.Configure(appender);

App.config ファイルに構成を追加すると、機能します。しかし、コードベースの構成が必要です...

4

1 に答える 1