Last active
December 11, 2017 20:19
-
-
Save janosorcsik/63cdb559977ada726da591337d6e4700 to your computer and use it in GitHub Desktop.
log4net extensions
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
using log4net.Layout.Pattern; | |
using log4net.Core; | |
using System.IO; | |
namespace LoggerExtensions | |
{ | |
public class MethodLocationPatternConverter : PatternLayoutConverter | |
{ | |
protected override void Convert(TextWriter writer, LoggingEvent loggingEvent) | |
{ | |
StackFrameItem[] stackFrames = loggingEvent.LocationInformation.StackFrames; | |
if (stackFrames != null && stackFrames.Length >= 1 && stackFrames[1] != null) | |
{ | |
writer.Write("{0}.{1}", stackFrames[1].ClassName, stackFrames[1].Method.Name); | |
} | |
else | |
{ | |
writer.Write("?"); | |
} | |
} | |
} | |
} |
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
using log4net.Layout; | |
using log4net.Util; | |
namespace LoggerExtensions | |
{ | |
public class MethodLocationPatternLayout : PatternLayout | |
{ | |
public MethodLocationPatternLayout() | |
{ | |
AddConverter(new ConverterInfo {Name = "methodlocation", Type = typeof(MethodLocationPatternConverter)}); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment