c# - log4net: Custom PatternLayoutConverter not being called -


Status: I want to show the method and line number for the code that logs a message. The problem is that I have an intermediate class that calls in log 4 net logger. Unfortunately, due to the current architectural issues, I can not get away from this intermediate class. The result is that I always look at the method and line number in the intermediate class.

So I tried to create a custom pattern lossout converter, according to this question:

I am also configuring the log4net program, again For architectural reasons, it is not possible to use an XML configuration file (I also find ridiculous that the preferred and only documented method of configuring log4net is through a stupid XML file, but it is a topic for another discussion is). That's why I followed this thread.

Everything works fine except my custom converter is never called. Here's the code for custom converters:

  Public class TVPatternLayout: PatternLayout {Public TVPatternLayout () {this.AddConverter ("logsite", typeof (TVPatternLayoutConverter)); }} Public class TVPatternLayoutConverter: PatternLayoutConverter {Protected Override Zero Convert (Text Writer Writer, Logging Event Logging Event) {StackTrace st = new StackTrace (); Int idx = 1; While (st.GetFrame (idx) .GetMethod (). Type declaration assembly == type (LogManager). Assembly) idx ++; Author.prakash (String.format ("{0}. {1} (line {2})", St. Gateframe (IDX) .GetMethod (.) Type the disclaimer name, st.GetFrame (idx) .GetMethod ( ) .name, st.GetFrame (idx) .GetFileLineNumber ())); }}  

And here's the code where I configure the logger:

  hierarchy hierarchy = (hierarchy) LogManager.GetRepository (); Hierarchy Configured = false; RollingFileAppender Appenders = New Rolling File Adapter (); AppenderName = LoggerName; Apder.file = realpath; Appender.AppendToFile = True; Adender Maximum min size = "8000"; Appenders Maxjole rollback = 2; TVPatternLayout Pattern Layout = New TVPatternLayout (); Pattern Layout Conversion pattern = log format; // contains% logsite, my custom option append.layout = patterned layout; Appender.activateOptions (); Hierarchy.Root.AddAppender (appender); Hierarchy Route = Level = Level. all; Hierarchy Configure = true; The problem was that I forgot to call ActivateOptions () on PatternalAutOut. Naturally, I understand a long question right after writing. 


Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -