简体   繁体   English

在Log4Net中为特定异常设置日志记录级别(适用于Episerver)

[英]Set logging level for specific exception in Log4Net (for Episerver)

How can I configure the logging levels for specific exceptions in Log4Net ? 如何在Log4Net中为特定异常配置日志记录级别?

Our application is currently generating multiple WebSocketException , at the WARNING logging level. 我们的应用程序当前正在WARNING日志级别生成多个WebSocketException We would, however, like to change if from WARNING to INFO to make our logs more readable. 但是,我们希望更改从WARNING到INFO以使我们的日志更具可读性。

The application is using the EPiServer Log4Net package, but the configuration should be the same. 该应用程序使用的是EPiServer Log4Net软件包,但配置应该相同。

Is this possible to configure from the Log4Net to do from .config file, or would one have to handle it in code? 这可以从Log4Net配置为.config文件,还是必须在代码中处理它?

Just filter out any entries you do not want, since WebSocketExceptions are not very interesting: 只是过滤掉你不想要的任何条目,因为WebSocketExceptions不是很有趣:

<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. 注意:Log4Net在使用StringMatchFilter时使用indexof,因此您可以查找部分字符串。 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. 使用Log4Net这应该像使用info而不是警告调用ILog一样简单。

Logger.Info("message");

instead of 代替

Logger.warn("message");

Depending on your setup it might be worth making the change in your xml 根据您的设置,可能值得在xml中进行更改

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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