My log4net conversion pattern looks like this
<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
The %file spits out the full path covering almost one full line in my console window.
How can I get just the file name (minus path).
Right now it looks like this
INFO [10] <c:\My Root Dir\Subdir\...........................\filename.cs> - My message
I want it to look like
INFO [10] <filename.cs> - My message
thank you
You can write your own pattern layout converter, maybe like this:
public class FileNamePatternConverter : PatternLayoutConverter
{
override protected void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
writer.Write(Path.GetFileName(loggingEvent.LocationInformation.FileName));
}
}
Then you configure it as follows:
<conversionPattern value="%5level [%thread] (%filename:%line) - %message%newline"" />
<converter>
<name value="filename" />
<type value="YourNamespace.FileNamePatternConverter" />
</converter>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With