The Log4Net mailing list is a great source of information about using log4Net, in this forum we collect all the messages in the log4net user list and some selected threads from the developer list.
| Author |
Messages |
|
Nik Hassan
 |
| 07/07/2004 7:24 PM |
|
Hi,
How do I add custom level , like TRACE on top of existing log4net levels ? I know that in log4j, I can extend Level class. Does anybody have sample code for log4net to do this ?
Thank you, Nik
|
|
|
|
|
Dag Christensen
 |
| 07/08/2004 9:38 AM |
|
I use appx this code to enable verbose logging (more detailed than debug). I haven't managed to, or tried very hard to, enable "verbose" logging using my log4net configuration file - any tips here is greatly appreciated. Verbose logging is only used by our developers while debugging code so the current code using an already existing separate configuration file works well.
class VBDLog : IVBDLog // interface defines Verbose,Debug,Info (...) methods { ... public static IVBDLog GetLogger(Type t) { Level level = log4net.spi.Level.VERBOSE; // actually read from an external configuration file. ILog logger = log4net.LogManager.GetLogger(t); if (logger.Level == null) { logger.Additivity = true; logger.Level = level; } return logger; } ... public void Verbose(object msg) { logger.Logger.Log( logger.Logger.Name, log4net.spi.Level.VERBOSE, msg); } }
Client code:
private static readonly IVBDLog log = VBDLog.GetLogger(typeof(SomeClass)); ...
if (log.IsVerboseEnabled) log.Verbose("Test");
Trace is also a predefined level in log4net just like Verbose (see the Level class)
I hope this helps,
Dag
|
|
|
|
|
Nicko Cadell
 |
| 07/30/2004 8:21 PM |
|
Nik,
There is an example extension in the log4net download that shows how to add a trace level to log4net. Have a look in extensions\net\1.0\log4net.Ext.Trace
Nicko
|
|
|
|
|
Henrik Johansson
 |
| 08/08/2004 4:35 PM |
|
Hi,
From an earlier post:
>Nik, > >There is an example extension in the log4net download that shows how to >add a trace level to log4net. >Have a look in extensions\net\1.0\log4net.Ext.Trace > >Nicko
But what if I want to add a new level YYY ? It is not possible to extend the log4net.spi.Level class (as it is sealed)? How should one do ?
Regards,
Henrik
|
|
|
|
|
Nicko Cadell
 |
| 08/10/2004 10:14 PM |
|
Henrik,
You can create a new Level using the Level(int,string) constructor. As long as the level is registered with the LoggerRepository it should be usable, however you do need to register it before you load the configuration file otherwise it will not be defined. You can create a new level programmatically as follows:
// Create the new level log4net.spi.Level level = new log4net.spi.Level(45000, "YYY");
// Register with the default LoggerRepository log4net.LogManager.GetLoggerRepository().LevelMap.Add(level);
// Configure log4net log4net.Config.DOMConfigurator.Configure();
Nicko
|
|
|
|
|
Nicko Cadell
 |
| 08/10/2004 10:14 PM |
|
Henrik,
You can create a new Level using the Level(int,string) constructor. As long as the level is registered with the LoggerRepository it should be usable, however you do need to register it before you load the configuration file otherwise it will not be defined. You can create a new level programmatically as follows:
// Create the new level log4net.spi.Level level = new log4net.spi.Level(45000, "YYY");
// Register with the default LoggerRepository log4net.LogManager.GetLoggerRepository().LevelMap.Add(level);
// Configure log4net log4net.Config.DOMConfigurator.Configure();
Nicko
|
|
|
|
|
therealdavidovitz-log4net@yahoo.com
 |
| 08/11/2004 9:28 AM |
|
After adding the new level how can you write to it, for example if i created level "audit"
i dont have log4net.Audittrail(...)
Thanks??
|
|
|
|
|
therealdavidovitz-log4net@yahoo.com
 |
| 08/11/2004 9:28 AM |
|
After adding the new level how can you write to it, for example if i created level "audit"
i dont have log4net.Audittrail(...)
Thanks??
|
|
|
|
|
Nicko Cadell
 |
| 08/11/2004 3:11 PM |
|
Henrik,
> After adding the new level how can you write to it, for > example if i created level "audit"
If you have a logger instance _log then you can write to it using your audiLevel as follows:
_log.Logger.Log(this.GetType().FullName, auditLevel, "your message here", null);
> i dont have log4net.Audittrail(...)
If you want to create your own log4net extension that adds a method like Audit(object) then you should have a look at the example extension in the log4net download that shows how to add a trace level to log4net.
Have a look in extensions\net\1.0\log4net.Ext.Trace
Cheers,
Nicko
|
|
|
|
|
Nicko Cadell
 |
| 08/11/2004 3:11 PM |
|
Henrik,
> After adding the new level how can you write to it, for > example if i created level "audit"
If you have a logger instance _log then you can write to it using your audiLevel as follows:
_log.Logger.Log(this.GetType().FullName, auditLevel, "your message here", null);
> i dont have log4net.Audittrail(...)
If you want to create your own log4net extension that adds a method like Audit(object) then you should have a look at the example extension in the log4net download that shows how to add a trace level to log4net.
Have a look in extensions\net\1.0\log4net.Ext.Trace
Cheers,
Nicko
|
|
|
|
|
|
| You are not authorized to post a reply. |
|
|
|
ActiveForums 3.7
|