jeff created LOG4NET-674:
----------------------------

             Summary: Document how to add custom levels to log4net repository
                 Key: LOG4NET-674
                 URL: https://issues.apache.org/jira/browse/LOG4NET-674
             Project: Log4net
          Issue Type: Improvement
          Components: Documentation
    Affects Versions: 2.0.8
            Reporter: jeff


It seem like in most cases just creating a level instance and using it will add 
it to the hierarchy but there appears to be an exception when using the 
eventlogappender level mapping configuration option. 

When configuring the eventlogappender level mapping, it was difficult to map 
custom log4net levels to a windows level.  I was unable to find documentation 
on how to load the custom log4net levels in to the map in the appender. The 
final solution that seemed to work was adding level to the configuration file, 
which I found on some other thread related to filtering. This allowed me to map 
my custom log4net audit levels to an equivalent event log level/keyword. 

 

Maybe some documentation on how to programmatically and via configuration add 
custom levels to log4net. A note on the eventlogappender level mapping about 
how to map custom events would be useful. 

 

via code...

public static class CustomLog4NetLevels
 {
 private static readonly Level successAudit = new Level(105000, "SuccessAudit");
 private static readonly Level failureAudit = new Level(106000, "FailureAudit");

/// <summary>
 /// Audit Sucess Level
 /// </summary>
 public static Level SuccessAudit \{ get => successAudit;}
 /// <summary>
 /// Audit Failure Level
 /// </summary>
 public static Level FailureAudit \{ get => failureAudit;}
 }

LogManager.GetRepository().LevelMap.Add(CustomLog4NetLevels.SuccessAudit); 
LogManager.GetRepository().LevelMap.Add(CustomLog4NetLevels.FailureAudit);

 

or via config

<log4net>
 <level>
 <name value="SuccessAudit" />
 <value value="105000" />
 </level>
 <level>
 <name value="FailureAudit" />
 <value value="106000" />
 </level>....



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to