Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Log4net, how to log a verbose message?

Tags:

log4net

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 can be checked in the Format function. The possible values are amongst others, Info, Debug, Error, Verbose. There are more, but these are the ones I'll be using mostly.

The actual log object only has the following methods:

Log.Info
Log.Debug
Log.Warn
Log.Error

As you can see - no verbose!

So how can I Log a verbose message, this is different to debug

Thanks in advance

like image 954
JL. Avatar asked Feb 17 '10 10:02

JL.


People also ask

What is logging verbose?

In software, verbose logging is the practice of recording to a persistent medium as much information as you possibly can about events that occur while the software runs. It's also worth mentioning that verbose logging is generally a mode that you can toggle on and off.

What is verbose debug logging?

Verbose logging is a type of computer logging method that involves more information than the standard or typical logging process. Typically, users can turn on verbose logging features to get more information about a system.


1 Answers

You can add a Verbose (or Trace level) to log4net by using extension methods. This is what I'm using:

public static class ILogExtentions
{
    public static void Trace(this ILog log, string message, Exception exception)
    {
        log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, 
            log4net.Core.Level.Trace, message, exception);
    }

    public static void Trace(this ILog log, string message)
    {
        log.Trace(message, null);
    }

    public static void Verbose(this ILog log, string message, Exception exception)
    {
        log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, 
            log4net.Core.Level.Verbose, message, exception);
    }

    public static void Verbose(this ILog log, string message)
    {
        log.Verbose(message, null);
    }

}

Usage example:

public class ClientDAO
{
    private static readonly log4net.ILog log = log4net.LogManager.GetLogger(typeof(ClientDAO));

    public void GetClientByCode()
    {
        log.Trace("your verbose message here");
        //....
    }
}

Source:

http://www.matthewlowrance.com/post/2010/07/14/Logging-to-Trace-Verbose-etc-with-log4net.aspx

like image 85
Wagner Danda da Silva Filho Avatar answered Oct 02 '22 22:10

Wagner Danda da Silva Filho