我真的很挣扎,所以这是我从 Enterprise 5 到 v6(流利)的工作升级。我提到在 Codeplex Migration PDF 中它仍然显示 EnterpriseLibraryContainer,它不再有效。
// app.config
<configSections>
<section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=6.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
</configSections>
// 我的记录器类使用 System; 使用 Microsoft.Practices.EnterpriseLibrary.Common.Configuration;使用 Microsoft.Practices.EnterpriseLibrary.Logging;
/// <summary>
/// Set up the Enterprise logging class
/// </summary>
public static class Logging
{
/// <summary>
/// Define the logging parameters
/// </summary>
public static void DefineLogger()
{
var builder = new ConfigurationSourceBuilder();
string loggerPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
builder.ConfigureLogging()
.WithOptions
.DoNotRevertImpersonation()
.LogToCategoryNamed("LogWriter")
.WithOptions.SetAsDefaultCategory()
.SendTo.RollingFile("Rolling Flat File Trace Listener")
.RollAfterSize(1000)
.FormatWith(new FormatterBuilder()
.TextFormatterNamed("Text Formatter")
.UsingTemplate(@"Timestamp: {timestamp}{newline}Message: {message},{newline}Category: {category},{newline}Severity: {severity},{newline}Title:{title},{newline}ProcessId: {localProcessId},{newline}Process Name: {localProcessName},{newline}Thread Name: {threadName}"))
.ToFile(loggerPath + Properties.Settings.Default.LogFileFolder);
// Reference app.config
using (DictionaryConfigurationSource configSource = new DictionaryConfigurationSource())
{
builder.UpdateConfigurationWithReplace(configSource);
Logger.SetLogWriter(new LogWriterFactory(configSource).Create());
}
}
}
最后在任何旧异常中:
Logger.Write("This is my log");
我希望这有助于节省大量时间。