log4net日志文件名中未包含进程ID [英] Process Id not coming in log4net log file name

查看:123
本文介绍了log4net日志文件名中未包含进程ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在我的日志文件名中包含进程ID信息,以便每次重新启动该应用程序时都创建一个新的日志文件.我从两个项目登录到同一文件.这是我的配置.

I'm trying to have the process Id information in my log file name so that a new log file is created every time the application is relaunched. I'm logging from two projects into the same file. This is my config.

<configuration>
    <configSections>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
    </configSections>

    <log4net>
        <appender name="NewLogForEveryRun" type="log4net.Appender.RollingFileAppender">
            <file value="c:\\testLogs\\TwoProjects-[%processid].txt" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%d [%t] %-5p %c - %m%n" />
            </layout>
        </appender>

        <logger name="ClassLibrary1">
            <level value="ERROR" />
            <maximumFileSize value="256KB" />
            <param name="Threshold" value="ERROR"/>
            <appender-ref ref="NewLogForEveryRun" />
        </logger>

        <logger name="ClassLibrary2">
            <level value="ERROR" />
            <maximumFileSize value="256KB" />
            <param name="Threshold" value="ERROR"/>
            <appender-ref ref="NewLogForEveryRun" />
        </logger>
    </log4net>
</configuration>

我提到%processid是为了在日志文件名中获取进程ID信息,但是当应用程序运行时,它将创建日志文件名为TwoProjects-[%processid].txt.实际的进程ID没有显示在文件名中.可能是什么原因?

I'm mentioning %processid to get the Process Id info in the log file name, but when the application runs, it creates the log file name as TwoProjects-[%processid].txt. The actual process Id is not shown in the file name. What could be the reason for this?

推荐答案

默认情况下,除非您指定说它包含模式,否则不会解析或处理文件值.

By default your file value is not parsed or processed unless you specify say it contains a pattern.

解决方案是更改行

<file value="c:\\testLogs\\TwoProjects-[%processid].txt" />

<file type="log4net.Util.PatternString" value="c:\\testLogs\\TwoProjects-[%processid].txt" />

这篇关于log4net日志文件名中未包含进程ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆