log4Net logging

I have my hangfire app and then imported other projects into visual studio.
One of those projects is already using log4Net.
Eventhough I had not configured logging for hangfire I am suddenly finding hangfire log entries in my child projects log file.

I truely have no clue how to get around this other than run the project as a complete separate application and calling it from a DOS prompt.

Any idea how I access the log4Net configuration in hangfire? I can’t seem to find any references.

thanks.

Hangfire uses liblog internally, so it binds automatically to log4net if available in your project.

Usually all hangfire loggers have this strict naming convention (Hangfire.*) and this allows you easily to filter them out of the general log4net stream. Just try this:

<logger additivity="false" name="Hangfire">
   <level value="INFO" />
   <appender-ref ref="HangfireLoggerAppender" />
</logger>>

2 Likes

Hey jordyto, your solution seems to have worked for me. Thanks for posting it!

The question relates to log4net, but as the document on logging links here, I’ll add the NLog way (in the NLog.config file), which is

<targets>
    <target xsi:type="File" name="logfile" fileName="${basedir}/App_Data/logs/myApp.log" />
    <target xsi:type="Null" name="BlackHole" formatMessage="false"  />
 </targets>

 <rules>
     <logger name="Hangfire.*" maxlevel="Warn" writeTo="BlackHole" final="true" /> 
     <logger name="*" minlevel="Debug" writeTo="logfile" />
 </rules>