The basic wire up seems straight forward but, I'm having difficulty understanding how to configure NLog as I might normally. Given the following setup, how would I set the configuration in order to get a text file dumped to a folder?
AppHost:
LogManager.LogFactory = new NLogFactory();
In App Logic:
ILog log = LogManager.GetLogger(GetType());
log.InfoFormat("Something happened");
A Config file like:
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" >
<targets>
<target name="console" xsi:type="ColoredConsole"
layout="${date:format=HH\:mm\:ss}|${level}|${stacktrace}|${message}" />
<target name="file" xsi:type="File" fileName="${specialfolder:folder=ApplicationData}/logs/App.log"
layout="${date}: ${message}" />
<target name="eventlog" xsi:type="EventLog" source="My App" log="Application"
layout="${date}: ${message} ${stacktrace}" />
</targets>
<rules>
<logger name="*" minlevel="Info" writeTo="file" />
<logger name="*" minlevel="Fatal" writeTo="eventlog" />
</rules>
Logging should ideally be specified before the AppHost is initialized, so all static initalizers for all classes in ServiceStack use the configured logger, e.g:
LogManager.LogFactory = new NLogFactory();
var appHost = new AppHost();
appHost.Init();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With