Created
August 20, 2012 09:46
-
-
Save lkaczanowski/3402710 to your computer and use it in GitHub Desktop.
ILog extension for TRACE and VERBOSE log4net levels
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public static class ILogExtentions | |
{ | |
private static readonly log4net.ILog log = | |
log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); | |
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); | |
} | |
} |
Hello Łukasz,
I already figured out how to use the ILogExtensions
class. The answers to my questions are:
- Just create a library from this class
- Yes
- It is up to the user to choose a
namespace
for the extension class
How to use it in the application?
It is necessary to import the namespace
, in my case log4net.Ext
. The application code would look like this.
using log4net.Ext;
public class MyApplication
{
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);
public void SomeMethod()
{
log.Trace("Trace log");
log.Verbose("Verbose log");
}
}
Would you know what to set in the config file for level
to have verbose
messages and switch off trace
messages?
I tried the following:
<level value="Verbose" />
But it did not work. Any idea how I can go fix that?
Many thanks,
Konstantin
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hello Łukasz,
I would like to use your
ILogExtensions
example. I just need a little more help to get started.My current situation:
log4net
library which I cannot changelog4net
library from the point abovelog4net
to have aTrace
andVerbose
logging levelI have the following questions:
ILogExtensions
class?log4net
,ILogExtensions
and my application.namespace
to I need to use forILogExtensions
?I have something like this in my head, but cannot get around the questions above:
I would really appreciate your help!
Many thanks
Konstantin