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 hidden or 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
namespacefor 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
ILogExtensionsexample. I just need a little more help to get started.My current situation:
log4netlibrary which I cannot changelog4netlibrary from the point abovelog4netto have aTraceandVerboselogging levelI have the following questions:
ILogExtensionsclass?log4net,ILogExtensionsand my application.namespaceto 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