Log4net, how to log a verbose message?

前端 未结 6 835
醉酒成梦
醉酒成梦 2020-12-14 09:53

I can log info messages without a problem, but can\'t figure out how to log verbose messages. Any help would be welcomed.

My problem is:

loggingEvent.Level

6条回答
  •  时光说笑
    2020-12-14 10:27

    Apache log4net has the following log levels:

    DEBUG < INFO < WARN < ERROR < FATAL

    For messages considered more verbose than informational messages (INFO), the DEBUG level is the option to go for. Writing debug messages should be as simple as:

    myLog.Debug("This is a pretty verbose message");
    

    If you write extremely many debug messages and/or the messages are costly to produce (eg involves heavy string concatenation), consider adding a conditional around the logging:

    if (myLog.IsDebugEnabled)
    {
        myLog.Debug("This is a pretty verbose message");
    }
    

    If you find yourself doing this often and want to DRY up your code, consider using extension methods for deferred message formatting, which will turn the above statement into this:

    Log.Debug( () => "This is a pretty verbose message" );  
    

提交回复
热议问题