Fluent APIを使用して、EntLibを使用したロギングのさまざまな設定オプションを処理しています。エンタープライズライブラリFluent APIとローリングログファイルローリング
loggingConfigurationセクションをコードで手動で構築しています。 RollingFlatFileTraceListenerが実際にファイルをロールアウトしない点を除いて、うまくいくようです。サイズ制限を尊重し、ファイルに書き込むデータ量を適切に制限しますが、実際には新しいファイルを作成してログを継続するわけではありません。
私はサンプルアプリケーションとapp.configでテストしましたが、動作するようです。だから私はそれが必要なように思えるすべての設定オプションはありますが、私は何かが欠けていると思います。ここで
は(ハードコードされた値で動作していないよう設定を表示するために)コードの基礎である: //流暢API するvar configBuilder =新しいConfigurationSourceBuilder(のための設定ビルダーを作成します) ;
//Start building the logging config section
var logginConfigurationSection = new LoggingSettings("loggingConfiguration", true, "General");
logginConfigurationSection.RevertImpersonation = false;
var _rollingFileListener = new RollingFlatFileTraceListenerData("Rolling Flat File Trace Listener", "C:\\tracelog.log", "----------------------", "",
10, "MM/dd/yyyy", RollFileExistsBehavior.Increment,
RollInterval.Day, TraceOptions.None,
"Text Formatter", SourceLevels.All);
_rollingFileListener.MaxArchivedFiles = 2;
//Add trace listener to current config
logginConfigurationSection.TraceListeners.Add(_rollingFileListener);
//Configure the category source section of config for flat file
var _rollingFileCategorySource = new TraceSourceData("General", SourceLevels.All);
//Must be named exactly the same as the flat file trace listener above.
_rollingFileCategorySource.TraceListeners.Add(new TraceListenerReferenceData("Rolling Flat File Trace Listener"));
//Add category source information to current config
logginConfigurationSection.TraceSources.Add(_rollingFileCategorySource);
//Add the loggingConfiguration section to the config.
configBuilder.AddSection("loggingConfiguration", logginConfigurationSection);
//Required code to update the EntLib Configuration with settings set above.
var configSource = new DictionaryConfigurationSource();
configBuilder.UpdateConfigurationWithReplace(configSource);
//Set the Enterprise Library Container for the inner workings of EntLib to use when logging
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
助けてください。