dmigo
dmigo

Reputation: 3029

Log4Net keeps writing Quartz.Net log to console

I'm using Quartz.net. Currently I'm issuing a problem with configuring log4net to write log to file. It keeps writing log entries to console.

Here is my App.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

    <configSections>
        <section name="quartz" type="System.Configuration.NameValueSectionHandler, System, Version=1.0.5000.0,Culture=neutral, PublicKeyToken=b77a5c561934e089" />
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>

    <common>
        <logging>
            <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net1211">
                <arg key="configType" value="INLINE" />
            </factoryAdapter>
        </logging>
    </common>

    <log4net>

        <appender name="FileAppender" type="log4net.Appender.FileAppender">
            <file type="log4net.Util.PatternString" value="Logs\Main-%date{yyyy-MM-dd_HH-mm-ss}.log" />
            <appendToFile value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date [%2thread] %-5level - %message%newline" />
            </layout>
        </appender>

        <root>
            <level value="DEBUG" />
            <appender-ref ref="FileAppender" />
        </root>

    </log4net>

    <quartz>
        <add key="quartz.scheduler.instanceName" value="MyScheduler" />
        <add key="quartz.threadPool.threadCount" value="3" />
        <add key="quartz.jobStore.type" value="Quartz.Simpl.RAMJobStore, Quartz" />
    </quartz>

</configuration>

And here is how I try to set logger in c# code:

var nameValueCollection = new Common.Logging.Configuration.NameValueCollection();
var adapter = new Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter(nameValueCollection);                
Common.Logging.LogManager.Adapter = adapter;

I'm out of ideas by now. Will appreciate any help.

Upvotes: 0

Views: 1565

Answers (1)

Rafał Rutkowski
Rafał Rutkowski

Reputation: 1449

The config looks correct. Most likely setting the Common.Logging.LogManager.Adapter manually overwrites the adapter set up in the config.

I'm using Quartz.net with the log4net adapter with almost exactly the same configuration and it works as expected without the need of using any of the Common.Logging API in the code.

Upvotes: 3

Related Questions