Configure Quartz.Net to write in separate file using NLog
Asked Answered
M

1

3

This is my config for nlog. What i'm trying to achieve is to have Quartz logs in separate file. But checking the logs folder i find only scheduler log file.

  <targets>
    <target xsi:type="File" name="f" fileName="${basedir}/logs/log-${shortdate}.log.json" layout="${json}" /> 
    <target xsi:type="File" name="scheduler" fileName="${basedir}/logs/log-${shortdate}.scheduler.log" layout="${message}" /> 
    <target xsi:type="Console" name="console" layout="${longdate} ${uppercase:${level}} ${message}" /> 
    </targets>
  <rules>
    <logger name="Quartz*" minlevel="Trace" writeTo="scheduler" final="true"/>
    <logger name="*" minlevel="Info" writeTo="console" />
    <logger name="*" minlevel="Trace" writeTo="f" />
  </rules>
</nlog>

Note: I also tried Quartz.* and change the order. But it dosen't help me.

Do i need any additional configuration to make it work?

Update 1: Sorry for misunderstanding. Logging itself working fine with Common.Logging. Andlogging file for Quartz that created also shows correct log. The problem is to have both of them, coz in my case for some reason quartz rule prevent creation of main one.

<common>
<logging>
  <factoryAdapter type="Common.Logging.NLog.NLogLoggerFactoryAdapter, Common.Logging.NLog31">
    <arg key="configType" value="FILE" />
    <arg key="configFile" value="~/NLog.config" />
  </factoryAdapter>
</logging>

this was configured from the beggining. The problems strarts when i added Quartz.

Meares answered 17/12, 2014 at 12:28 Comment(4)
usefull #6570436?Stagy
As @Stagy points out you need to configure Common logging to redirect its logging to NLog.Estrous
The first code snippet is that located in NLog.Config or web/app.config? you have configured Common.Logging to use NLog.Config.Estrous
Yes, Nlog.Config is separate configuration for my project. We keep all nlog config thereMeares
B
1

Logging itself working fine with Common.Logging. Andlogging file for Quartz that created also shows correct log. The problem is to have both of them, coz in my case for some reason quartz rule prevent creation of main one.

Take "final=true" out of your first logger rule so that it continues to process the other rules. I know this is old, but that would solve your problem:

final – no rules are processed after a final rule matches

Blackmun answered 10/6, 2019 at 18:21 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.