Can i use multiple targets for logging with NLog

3,581 views
Skip to first unread message

deeps

unread,
Dec 11, 2012, 5:50:00 AM12/11/12
to nlog-...@googlegroups.com
Hello,

I want to log for one of my project and i am using NLog. I was logging in a file (using target as file). But now my client 
wants logging in gibraltar. so i added one more target in my Nlog.config and also web.config.

NLog.config is like :
      autoReload="true">
  <extensions>
    <add assembly="Gibraltar.Agent.NLog2" />
  </extensions>
  <targets>
    <target name="file" xsi:type="File" fileName="${basedir}/logs/${shortdate}/${logger}.txt" />
    <target name="Gibraltar" xsi:type="Gibraltar" />
  </targets>
  <rules>
    <logger name="*" minlevel="Debug" writeTo="Gibraltar" />
    <logger name="*" minlevel="Warn" writeTo="Gibraltar" />
    <logger name="*" minlevel="Error" writeTo="Gibraltar" />
    <logger name="*" minlevel="Fatal" writeTo="Gibraltar" />
    
    <logger name="*" minlevel="Info" writeTo="file" />
    <logger name="*" minlevel="Warn" writeTo="file" />
    <logger name="*" minlevel="Error" writeTo="file" />
    <logger name="*" minlevel="Fatal" writeTo="file" />
  </rules>
</nlog>




web.config section for logging with Nlog in Gibraltar :

<configSections>    
    <section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
</configSections>

    <extensions>
      <add assembly="Gibraltar.Agent.NLog2" />
      <!--Contains GibraltarTarget class marked as "Gibraltar" target type-->
    </extensions>
    <targets>
      <target name="Gibraltar" xsi:type="Gibraltar" />
      <!--Define a named target using the "Gibraltar" target type-->
    </targets>
    <rules>
      <logger name="*" minlevel="Trace" writeTo="Gibraltar" />
      <logger name="*" minlevel="Debug" writeTo="Gibraltar" />
      <logger name="*" minlevel="Warn" writeTo="Gibraltar" />
      <logger name="*" minlevel="Error" writeTo="Gibraltar" />
      <logger name="*" minlevel="Fatal" writeTo="Gibraltar" />
      <!--Send all logging to the "Gibraltar" named target-->
    </rules>
  </nlog>


But now the logs are only generated in Gibraltar and not in the files. 
I want the logs in file too.

What should i do ?

Thanks.

Jason LaFlair

unread,
Dec 11, 2012, 6:02:34 PM12/11/12
to nlog-...@googlegroups.com
You can specify multiple targets in your logger rule.

<rules>
    <logger name="*" minlevel="Debug" writeTo="Gibraltar" />  <!-- just logs to Gibraltar target -->
    <logger name="*" minlevel="Info" writeTo="file" />  <!-- just logs to file target -->
    <logger name="*" minlevel="Warn" writeTo="Gibraltar,file" />  <!-- logs to both targets -->
    <logger name="*" minlevel="Error" writeTo="Gibraltar,file" />  <!-- logs to both targets -->
    <logger name="*" minlevel="Fatal" writeTo="Gibraltar,file" />  <!-- logs to both targets -->
</rules>

--
You received this message because you are subscribed to the Google Groups "NLog-Users" group.
To post to this group, send email to nlog-...@googlegroups.com.
To unsubscribe from this group, send email to nlog-users+...@googlegroups.com.
Visit this group at http://groups.google.com/group/nlog-users?hl=en.
 
 

Reply all
Reply to author
Forward
0 new messages