简体   繁体   中英

Set logging level for specific exception in Log4Net (for Episerver)

How can I configure the logging levels for specific exceptions in Log4Net ?

Our application is currently generating multiple WebSocketException , at the WARNING logging level. We would, however, like to change if from WARNING to INFO to make our logs more readable.

The application is using the EPiServer Log4Net package, but the configuration should be the same.

Is this possible to configure from the Log4Net to do from .config file, or would one have to handle it in code?

Just filter out any entries you do not want, since WebSocketExceptions are not very interesting:

<filter type="log4net.Filter.StringMatchFilter">
  <stringToMatch value="WebSocketException" />
  <acceptOnMatch value="false" />
</filter>

Note: Log4Net uses indexof when using StringMatchFilter, so you can look for partial strings. Do take in mind that it is case sensitive.

With Log4Net This should be as simple as calling the ILog with info instead of warn.

Logger.Info("message");

instead of

Logger.warn("message");

Depending on your setup it might be worth making the change in your xml

<log4net> 
  <appender name="appenders_name">
  ... other settings
   <root>
       <level value="INFO" />
   </root>
  </appender>
</log4net>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM