fixed path.combine null exception if the config doesnt exist

This commit is contained in:
chris.watts90@outlook.com 2017-02-16 22:16:37 +00:00
parent ebfced87ee
commit 1babd514ce

View File

@ -13,11 +13,12 @@ namespace NLogLogger
private NLog.Logger _logger;
public NLogger()
{
var nlogConfigPath = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), ConfigurationManager.AppSettings["NLogConfigFilePath"])).LocalPath;
if (nlogConfigPath == null)
var nlogConfigPathOption = ConfigurationManager.AppSettings["NLogConfigFilePath"];
if (nlogConfigPathOption == null)
{
throw new ArgumentNullException("nlogConfigPath");
}
var nlogConfigPath = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), nlogConfigPathOption)).LocalPath;
LogManager.Configuration = new XmlLoggingConfiguration(nlogConfigPath);
_logger = LogManager.GetLogger("");
}