如何从log4net中的日志文件名中删除日期

时间:2014-06-11 03:58:29

标签: log4net log4net-configuration

我想要的日志文件只是" Log.txt.0"我不希望将日期附加到日志文件中。即使没有添加日期模式,我也会将日期附加到日志文件中。

<?xml version="1.0"?>
<configuration>
<configSections>
    <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
<log4net>
    <appender name="Console" type="log4net.Appender.ConsoleAppender">
        <layout type="log4net.Layout.PatternLayout">
            <!-- Pattern to output the caller's file name and line number -->
            <conversionPattern value="%5level [%thread] (%file:%line) - %message%newline" />
        </layout>
    </appender>
    <appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
        <lockingModel type="log4net.Appender.FileAppender+MinimalLock"/>
        <!-- Log files are logged in the AppData path for Traylogs.log -->
        <file value="${APPDATA}\Project\Application\My Application\Logs.txt"/>
        <staticLogFileName value="false" />
        <appendToFile value="true" />
        <countDirection value="1"/>
        <appendToFile value="true" />
        <maximumFileSize value="100KB" />
        <maxSizeRollBackups value="2" />
        <layout type="log4net.Layout.PatternLayout">            
            <conversionPattern value="%level %thread %logger - %message%newline" />
        </layout>
    </appender>
    <root>
        <level value="ALL" />
        <appender-ref ref="Console" />
        <appender-ref ref="RollingFile" />
    </root>
</log4net>
<startup>
    <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0"/>
</startup>
<system.serviceModel>
    <bindings />
    <client />
</system.serviceModel>
</configuration>

如何删除附加到日志文件的日期?

1 个答案:

答案 0 :(得分:1)

默认情况下,我们有datePattern = ".yyyy-MM-dd"(所以你有这个后缀)。因此,如果日志文件名中不需要日期,则可以设置<datePattern value="" />(空字符串而不是默认值)。