如何每天使用EnterpriseLibrary文件
我有以下代码:
private static void configureLog(string logFile)
{
var builder = new ConfigurationSourceBuilder();
builder.ConfigureLogging()
.LogToCategoryNamed("General")
.WithOptions.SetAsDefaultCategory()
.SendTo.FlatFile("Log File")
.FormatWith(new FormatterBuilder()
.TextFormatterNamed("Text Formatter")
.UsingTemplate("{message}"))
.ToFile(logFile).WithHeader(string.Empty).WithFooter(string.Empty);
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);
}
但它总是生成一个日志文件。
答案 0 :(得分:0)
您可以使用Quartz.NET为每天安排此流程并调用相同的方法。
答案 1 :(得分:0)
我使用RollingFile配置解决了这个问题:
var builder = new ConfigurationSourceBuilder();
builder.ConfigureLogging()
.LogToCategoryNamed("General")
.WithOptions.SetAsDefaultCategory()
.SendTo.RollingFile("Log File")
.RollEvery(Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollInterval.Day)
.UseTimeStampPattern("yyyyMMdd")
.WhenRollFileExists(Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.RollFileExistsBehavior.Overwrite)
.FormatWith(new FormatterBuilder()
.TextFormatterNamed("Text Formatter")
.UsingTemplate("{message}"))
.ToFile(SettingsHelper.LogFilePath)
.WithHeader(string.Empty)
.WithFooter(string.Empty);
var configSource = new DictionaryConfigurationSource();
builder.UpdateConfigurationWithReplace(configSource);
EnterpriseLibraryContainer.Current = EnterpriseLibraryContainer.CreateDefaultContainer(configSource);