首页 新闻 搜索 专区 学院

关于log4net自定义log文件名的问题.

0
悬赏园豆:20 [已解决问题] 解决于 2010-09-07 17:09

我想在项目中用log4net生成自定义的文件名,如,20100902.log.

我想这个在web.config里是做不了的.

就用程序配.可使老是报

 

警告 1“log4net.Appender.FileAppender.FileAppender(log4net.Layout.ILayout, string)”已过时:“Instead use the default constructor and set the Layout & File properties”E:\ConpanyWeb\500kv\500kv\ahead\logtest.aspx.cs3015500kv

 

求解决

问题补充: BasicConfigurator.Configure( new FileAppender(new PatternLayout("%d-%m%n"), "LOG/" + DateTime.Now.ToString("yyyyMMdd") + ".log")); 我是用这种方式配置的.
鲤伴先生的主页 鲤伴先生 | 初学一级 | 园豆:9
提问于:2010-09-02 16:37
< >
分享
最佳答案
0

给你个可用的配置:


    <configSections>
        <sectionGroup name="common">
            <section name="logging" type="Common.Logging.ConfigurationSectionHandler, Common.Logging" />
        </sectionGroup>
        <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
        <sectionGroup name="spring">
            <section name="parsers" type="Spring.Context.Support.NamespaceParsersSectionHandler, Spring.Core" />
            <section name="context" type="Spring.Context.Support.ContextHandler, Spring.Core" />
            <section name="objects" type="Spring.Context.Support.DefaultSectionHandler, Spring.Core" />
        </sectionGroup>
    </configSections>
    <common>
        <logging>
            <factoryAdapter type="Common.Logging.Log4Net.Log4NetLoggerFactoryAdapter, Common.Logging.Log4Net">
                <arg key="configType" value="INLINE" />
            </factoryAdapter>
        </logging>
    </common>
    <log4net>
        <appender name="FileAppender" type="log4net.Appender.FileAppender">
            <file type="log4net.Util.PatternString" value="Logs\%date{yyyMMdd}.log" />
            <appendToFile value="true" />
            <layout type="log4net.Layout.PatternLayout">
                <conversionPattern value="%date %-5level - %message%newline" />
            </layout>
        </appender>
        <root>
            <level value="INFO" />
            <appender-ref ref="FileAppender"/>
        </root>
        <logger name="Spring">
            <level value="WARN" />
        </logger>
        <logger name="Clubank">
            <level value="DEBUG" />
        </logger>
    </log4net>

收获园豆:20
HUHU慈悲 | 大侠五级 |园豆:9973 | 2010-09-02 17:02
可以使用,但是IsDebugEnabled = false. 我就是想要用Debug
鲤伴先生 | 园豆:9 (初学一级) | 2010-09-02 17:24
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册