I really struggled with this, so here is my working upgrade from Enterprise 5 to v6 (free). I mention that the Codeplex Migration PDF file still displays an EnterpriseLibraryContainer, which is no longer valid.
//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>
// my class is logger using the system; using Microsoft.Practices.EnterpriseLibrary.Common.Configuration; using 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()); } } }
Finally, in any old exception:
Logger.Write("This is my log");
Hope this helps save a lot of time.
source share