Majkel
Majkel

Reputation: 93

How to shorten log4net logger path

my log4net conversionpattern displays full path to class:

    11:40:11,209 [C:\Users\martin\Documents\Visual Studio 2015\Projects\MyProject\MyProject\ViewModels\MainViewModel.cs] DEBUG - Test log

Is there a way how to shorten path to class name only?

    11:40:11,209 [MainViewModel.cs] DEBUG - Test log

Upvotes: 3

Views: 365

Answers (3)

Nikson Kanti Paul
Nikson Kanti Paul

Reputation: 3440

use conversion pattern value like following

<conversionPattern value="[%d{yyyy-MM-dd HH:mm:ss}] [%t] %-5p %c - %m%n" />

See more in about conversionPattern

Upvotes: 1

Vishnu Babu
Vishnu Babu

Reputation: 1275

in the log4net configuration try using

<layout type="log4net.Layout.PatternLayout">
 <conversionPattern value="%date [%-4thread] %-5level %logger{1} - %message%newline"/>
</layout>

Upvotes: 1

ne1410s
ne1410s

Reputation: 7092

It's also my typical experience to have trouble with the odd conversion nomenclature and the scant levels of documentation that seems to be available in a central location.

I have adapted the conversion pattern I normally use to get you something similar to what you requested:

<conversionPattern value="%d %-22.22c{1} %-5p - %m%n"/>

The %-22.22c{1} bit is the shortened class name (I guess) :)

The above will result in something like:

2015-12-28 11:11:26,892 MyClass DEBUG - Test log

Upvotes: 1

Related Questions