Skip to content

Commit

Permalink
(GH-1378) allow external log4net config file
Browse files Browse the repository at this point in the history
If choco finds a log file next to it by the name of `log4net.config.xml`
(a little bit different on purpose), it will use that file instead of
the built-in configuration for log4net. Use this with caution as it
could cause certain logging items to disappear when the external config
does not include the necessary logging sections. It may even cause
choco to error.
  • Loading branch information
ferventcoder committed Aug 6, 2017
1 parent 64cc462 commit eaad67d
Showing 1 changed file with 19 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -47,24 +47,33 @@ public sealed class Log4NetAppenderConfiguration
public static void configure(string outputDirectory = null, params string[] excludeLoggerNames)
{
GlobalContext.Properties["pid"] = System.Diagnostics.Process.GetCurrentProcess().Id;

var assembly = Assembly.GetExecutingAssembly();
var resource = ApplicationParameters.Log4NetConfigurationResource;
if (Platform.get_platform() != PlatformType.Windows)

var xmlConfigFile = Path.Combine(ApplicationParameters.InstallLocation, "log4net.config.xml");
if (File.Exists(xmlConfigFile))
{
// it became much easier to do this once we realized that updating the current mappings is about impossible.
resource = resource.Replace("log4net.", "log4net.mono.");
XmlConfigurator.ConfigureAndWatch(new FileInfo(xmlConfigFile));
_logger.DebugFormat("Configured Log4Net configuration from file ('{0}').", xmlConfigFile);
}
Stream xmlConfigStream = assembly.get_manifest_stream(resource);
else
{
var assembly = Assembly.GetExecutingAssembly();
var resource = ApplicationParameters.Log4NetConfigurationResource;
if (Platform.get_platform() != PlatformType.Windows)
{
// it became much easier to do this once we realized that updating the current mappings is about impossible.
resource = resource.Replace("log4net.", "log4net.mono.");
}
Stream xmlConfigStream = assembly.get_manifest_stream(resource);

XmlConfigurator.Configure(xmlConfigStream);
XmlConfigurator.Configure(xmlConfigStream);

_logger.DebugFormat("Configured Log4Net configuration ('{0}') from assembly {1}", resource, assembly.FullName);
}

if (!string.IsNullOrWhiteSpace(outputDirectory))
{
set_file_appender(outputDirectory, excludeLoggerNames);
}

_logger.DebugFormat("Configured {0} from assembly {1}", resource, assembly.FullName);
}

/// <summary>
Expand Down

0 comments on commit eaad67d

Please sign in to comment.