I am running a multithreaded C # .NET 4.5 application.
Running on my local Windows 7 laptop, NLog logs all my messages. I publish the application using Visual Studio ... copy the published application to Windows Server 2008 ... and run the application on the server: this leads to a missed log message. Can someone help me understand WHY and how can I fix this or suggest an alternative to NLog?
My configuration file is as follows:
I tried this without "async = true"
<targets async="true"> <target xsi:type="ColoredConsole" name="ColoredConsole" layout="${date} ${level} ${message} ${event-context:item=AlgID} " /> <target name="xmlfile" xsi:type="File" fileName="C:\QRT\Logs\LogEmiter.Nlog.xlog" keepFileOpen="true" layout="${log4jxmlevent}" /> <target xsi:type="File" name ="LogFile" fileName="C:\QRT\Logs\QRTLog-${shortdate}.log" layout ="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}|${level}|${threadid}|${threadname}|${event-properties:item=FromID}|${message}${exception:format=tostring} "/> <target xsi:type="File" name ="TapeLogFile" fileName="C:\QRT\Logs\QRTMarketLog.txt" layout ="${date:format=yyyy-MM-dd HH\:mm\:ss.fff}|${level}|${message}"/> </targets> <rules> <logger name ="TapeLogFile" minlevel="Trace" writeTo="TapeLogFile" /> <logger name ="TapeLogFile" minlevel="Trace" writeTo="ColoredConsole" final="true"/> <logger name="*" minlevel="Trace" writeTo="ColoredConsole" /> <logger name="*" minlevel="Trace" writeTo="xmlfile" /> <logger name="*" minlevel="Trace" writeTo="LogFile" /> </rules> </nlog>
I log messages as follows:
In my typical class, I would initialize my helper class NLog as such:
private void InitliazlieLogger() { LogManager.ThrowExceptions = true; m_logger = new NLogHelper(LogManager.GetCurrentClassLogger()); m_logger.Set("FromID", "Email");
I have an NLog helper class ...
public NLogHelper(Logger Logger) { m_logger = Logger; m_properties = new Dictionary<string, object>(); } public void Debug(string Message, params object[] Args) { m_logger.Debug() .Message(Message, Args) .Properties(m_properties) .Write(); notify(Severity.Debug, Message); }
The problem is that some log messages are simply skipped. I added my own logging class, which wrote the file manually, and inserted the call into NLogHelper.Debug, and I found that the file I wrote manually had a full set of log messages, but there was no NLog output.
Again, this works on my laptop, but it doesn’t work on Windows Server 2008. My server has .NET 4.6.1 installed. It seems that I only have 4.5.2 on my Windows 7 machine. Could this be?
As a note: if I upload all my source files to the server and use Visual Studio on the server to compile the same code, does NLog seem to work?!?
-Confused.
Thanks red