如果我在C#中使用log4net,如何在log.config中设置file.log的路径和大小? [英] How can I set the path and the size of the file.log in log.config if I use log4net in C# ?

查看:69
本文介绍了如果我在C#中使用log4net,如何在log.config中设置file.log的路径和大小?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,



我使用框架log4net为我的应用程序C#编写logFile。



我想手动设置log.config中file.log的路径和大小。



我的log.config文件是:



Hello,

I use the framework log4net for write the logFile for my application C#.

I want to set manually the path and the size of the file.log in log.config.

My log.config file is :

  <?xml version="1.0" encoding="utf-8" ?>
       <!-- Xml file that contains the configuration of Log4net -->
       <configuration>
       <configSections>
       <section name="log4net" type="System.Configuration.IgnoreSectionHandler"/>
       </configSections>
       <log4net>
       <!-- RollingFileAppender : Writing events to a file. Ability to log on multiple files  based on date and time. -->
      <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
          <file value="C:\...\x.log" />
          <appendToFile value="true" />
          <rollingStyle value="Size" />
          <maxSizeRollBackups value="10" />
          <maximumFileSize value="1MB" />
          <staticLogFileName value="true" />
          <layout type="log4net.Layout.PatternLayout">
             <conversionPattern value="%date [%thread] %-5level %logger - %message%newline" />
          </layout>
     </appender>
      <!-- We define the root logger to DEBUG level and is associated with the  RollingFileAppender appender -->
    <root>
        <level value="DEBUG" />
        <!-- <appender-ref ref="ConsoleAppender" /> -->
        <appender-ref ref="RollingFileAppender" />
    </root>
</log4net>





你能帮我解决路径



Can you help me how to put the path

<file value="C:\...\x.log" />

和尺寸

<maximumFileSize value="1MB" />




提前谢谢。

of file.log from my Form C# ?

Thank you in advance.

推荐答案

阅读: http://stackoverflow.com/questions/16336917/can-you-configure-log4net-in-code-instead-of-using-a-config-file [ ^ ]



或尝试使用我的文章:用于log4net的迷你直接替换 [ ^ ]
Read this : http://stackoverflow.com/questions/16336917/can-you-configure-log4net-in-code-instead-of-using-a-config-file[^]

or try using my article here : Mini Drop-in Replacement for log4net[^]


这篇关于如果我在C#中使用log4net,如何在log.config中设置file.log的路径和大小?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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