简体   繁体   English

我正在使用 log4net 进行日志记录,但它没有写入日志

[英]i am using log4net for logging purpose but it is not writing the logs

I have made changes into my Web.Config我已经对我的 Web.Config 进行了更改

I am using .net 4.0我正在使用 .net 4.0

I am using log4net i have added the reference我正在使用 log4net 我已经添加了参考

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

<log4net debug="true">
  <appender name="RollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
    <file value="C:\Users\n.gupta\Desktop\CacheService.log"/>
    <appenToFile value="true" />
    <rollingStyle value="Size"/>
    <maxsixeRollBackups value="10"/>
    <maximumFileSize value="10Mb"/>
    <staticLogFileName value="true"/>
    <layout type="log4net.PatternLayout">
      <conversionPattern value="%-5p %d %5rms %-22.22c{1} %-18.18M - %m%n"/>
    </layout>
  </appender>
  <root>
    <level value="DEBUG"/>
    <appender-ref ref="RollingLogFileAppender" />
  </root>
</log4net>

I have made changes in AssemblyInfo.cs我在 AssemblyInfo.cs 中进行了更改

[assembly:log4net.Config.XmlConfigurator(ConfigFile="Web.config",Watch=true)]

I have add the debugging into my controller我已将调试添加到我的控制器中

I have a shipment controller which contains a creating method in whihc i am logging我有一个装运控制器,其中包含我正在记录的创建方法

public class ShipmentController : BaseController
{
    private static readonly ILog logger = ogManager.GetLogger(typeof(ShipmentController));
    public ActionResult ShipmentCreation()
    {
        //I have attached the debug code for the message
        logger.Debug("Hello I am in Shipment creation Method");
    }
}

The file being created but it in not appending anything正在创建的文件,但它没有附加任何内容

You have at least two syntax errors in your config's XML:您的配置的 XML 中至少有两个语法错误:

<appenToFile value="true" />
<rollingStyle value="Size"/>
<maxsixeRollBackups value="10"/>

appendToFile and maxSize... at the very least, must be corrected. appendToFilemaxSize...至少,必须更正。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM