added console target to NLogConfig.xml, to help debugging on console, rather than using console.writelines.

This commit is contained in:
Chris.Watts90@outlook.com 2018-03-08 09:18:20 +00:00
parent fb068cbdf2
commit 9ba44d273e
2 changed files with 6 additions and 2 deletions

View File

@ -4,8 +4,12 @@
autoReload="true"> autoReload="true">
<targets> <targets>
<target name="viewer" xsi:type="Chainsaw" address="udp://127.0.0.1:4000" /> <target name="viewer" xsi:type="Chainsaw" address="udp://127.0.0.1:4000" />
<target xsi:type="Console" name="consoleViewer"
layout="${longdate}|${level:uppercase=true}|${message}"
detectConsoleAvailable="true" />
</targets> </targets>
<rules> <rules>
<logger name="*" minlevel="Trace" writeTo="viewer" /> <logger name="*" minlevel="Trace" writeTo="viewer" />
<logger name="*" minlevel="Trace" writeTo="consoleViewer" />
</rules> </rules>
</nlog> </nlog>

View File

@ -9,14 +9,14 @@ namespace NLogLogger
{ {
public class NLogger:ILogger public class NLogger:ILogger
{ {
private NLog.Logger _logger; private readonly Logger _logger;
public NLogger() public NLogger()
{ {
var nlogConfigPathOption = var nlogConfigPathOption =
ConfigurationHandler.ConfigurationHandler.GetConfiguration("NLogConfigFilePath"); ConfigurationHandler.ConfigurationHandler.GetConfiguration("NLogConfigFilePath");
if (nlogConfigPathOption == null) if (nlogConfigPathOption == null)
{ {
throw new ArgumentNullException("nlogConfigPath"); throw new ArgumentNullException("nlogConfigPath", "NLogConfigFilePath missing from application config file.");
} }
var nlogConfigPath = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), nlogConfigPathOption)).LocalPath; var nlogConfigPath = new Uri(Path.Combine(Path.GetDirectoryName(Assembly.GetEntryAssembly().CodeBase), nlogConfigPathOption)).LocalPath;
LogManager.Configuration = new XmlLoggingConfiguration(nlogConfigPath); LogManager.Configuration = new XmlLoggingConfiguration(nlogConfigPath);