Gul*_*llu 5 c# log4net log4j log4cxx log4net-configuration
我的log4net转换模式如下所示
<conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
Run Code Online (Sandbox Code Playgroud)
%文件在我的控制台窗口中吐出几乎覆盖整行的完整路径.
我怎样才能得到文件名(减去路径).
现在它看起来像这样
INFO [10] <c:\My Root Dir\Subdir\...........................\filename.cs> - My message
Run Code Online (Sandbox Code Playgroud)
我希望它看起来像
INFO [10] <filename.cs> - My message
Run Code Online (Sandbox Code Playgroud)
谢谢
您可以编写自己的模式布局转换器,也许像这样:
public class FileNamePatternConverter : PatternLayoutConverter
{
override protected void Convert(TextWriter writer, LoggingEvent loggingEvent)
{
writer.Write(Path.GetFileName(loggingEvent.LocationInformation.FileName));
}
}
Run Code Online (Sandbox Code Playgroud)
然后您按如下方式配置它:
<conversionPattern value="%5level [%thread] (%filename:%line) - %message%newline"" />
<converter>
<name value="filename" />
<type value="YourNamespace.FileNamePatternConverter" />
</converter>
Run Code Online (Sandbox Code Playgroud)