log4net: Configure to ignore messages from a specific class

前端 未结 5 813
孤独总比滥情好
孤独总比滥情好 2020-12-02 15:24

Is there a way to have the log4net configuration ignore a specific class? For example, we generally create a log in every class. Similar to this:

private sta         


        
5条回答
  •  遥遥无期
    2020-12-02 15:48

    I would suggest using Filters as well. However, since I struggled finding the whole picture when I was trying to implement the filter I am posting a sample snippet of the Configutation file I created which points out where filters go.

    The filter you are going for in this case would be

    log4net.Filter.LoggerMatchFilter ----(Matches against a the start of the logger name.)

    Hint: In the config file for Log4Net it is important where you put your tags and the priority of them actually matters. So in this case tag comes after the opening tag and before it's tag.

    
    
        
            

    In this technique you can have multiple appenders which you can redirect the logging results of a specific logger to a separate appender instead of ignoring them. Such as one appender for all logs and one for the filtered out logs for a specific class.

提交回复
热议问题