1

I'm using NLog in my MVC Web Api application. I installed NLog using NuGet package manager and configured my log target in Nlog.conf file which got created.

 <targets>
   <target xsi:type="EventLog"
           name="eventlog"
           source="ImageService"
           machineName="."
           log="Application"
           layout="${longdate}|${level}|${message}"/>
 </targets>
<rules>
   <logger name="*" minlevel="Debug" writeTo="eventlog" />
 </rules>

Then in registered a new event using powershell.

New-EventLog -Logname Application -Source ImageService

Now in C# code I'm doing following

Logger _log = LogManager.GetCurrentClassLogger();
_log.Info("Demo message);

But when I go to Event Viewer -> Windows Log -> Application and filter it based on source name ImageService it doesn't show any entry there.

If it is of any significance .The above logger code is written in separate Class library which is then referenced in the Web application and the log function is called.

Is there anything wrong with my target and rule configuration ?

kaysush
  • 4,797
  • 3
  • 27
  • 47
  • Do you have the nlog.config file in your web project? – nemesv Apr 07 '16 at 12:40
  • no the file is in library project only.. but it gets copies to bin/Debug after build so I think it gets available during runtime Am I correct ? – kaysush Apr 08 '16 at 04:56
  • No, it won't be copied to your web project automatically. You need to have the nlog.config next to your web.config to make it work. So the ideal solution would be to move the nlog.config to your web project or at least add as a linked item to that project or copy there in a post-build event, etc. – nemesv Apr 08 '16 at 05:45
  • Oops.. that was a very naive mistake. Thanks.. It fixed the issue :) – kaysush Apr 08 '16 at 07:09
  • you should mark your question as answered. – Julian Apr 15 '16 at 07:44

0 Answers0