How to set LogLevel to error in log4net for hangfire
Asked Answered
C

2

7

We have a web application and we are using log4net for logging. Recently I installed hangfire and now my log table (sqlserver db) is full of log enteries from hangfire. I want to minimise this to error and exceptions only. I believe I can set it by setting LogLevel to error but where exactly I need to do that.

Thanks

Chun answered 2/5, 2016 at 14:21 Comment(0)
S
10

Add this logger to your web.config (log4net section)

<logger additivity="false" name="Hangfire">
   <level value="ERROR" />
   <appender-ref ref="HangfireLoggerAppender" />
</logger>
Shantung answered 2/5, 2016 at 14:45 Comment(5)
Thank you so much :) Its working on my local. Once it works on production I will accept your answer.Chun
@Martino Bordin ThanksCzarist
more detail and an example for NLog are on the hangfire discussion forum discuss.hangfire.io/t/log4net-logging/1280/2Advertisement
how to set value to level node if I want both "Debug" and "ERROR" levels?Pet
just remember to set your own appender name used in log4net configuration in tag <appender-ref ref="..." /> shown in the answer above.Homograph
C
4

Adding to what @Martino mentioned above here is the exact location to add that tag in log4net section:

<log4net debug="true">
  <root>
    <level value="ALL" />
    <appender-ref ref="LogFileAppender" />
  </root>
  <appender name="LogFileAppender" type="log4net.Appender.FileAppender">
    <file type="log4net.Util.PatternString" value="%property{LogFileName}" />
    <appendToFile value="true" />
    <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="%date %level %logger - %message%newline" />
    </layout>
  </appender>
  <logger additivity="false" name="Hangfire">
    <level value="ERROR" />
    <appender-ref ref="HangfireLoggerAppender" />
  </logger>
</log4net>
Countermand answered 15/11, 2019 at 8:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.