我已經嘗試了幾種方法來調整,但Log4Net文件記錄器沒有記錄任何東西在我的MVC3網絡應用程序。爲什麼Log4Net不寫錯誤日誌?
我缺少什麼?我也沒有得到任何錯誤。
log4net dll被添加到應用程序,它指向本地副本。
1主要的web.config:
<appSettings>
<add key="Log4NetConfigFilename" value="log4net.config" />
<add key="Log4NetConfigFilePath" value="C:\DEV\App\source\App.Web\log4net.config" />
</appSettings>
2的Global.asax.cs
protected void Application_Start()
{
log4net.Config.XmlConfigurator.Configure();
}
3 Log4net.config文件:
<?xml version="1.0" encoding="utf-8" ?>
<log4net>
<logger name="MyLogger">
<level value="ALL" />
<appender-ref ref="MyRollingLogFileAppender" />
</logger>
<appender name="MyRollingLogFileAppender" type="log4net.Appender.RollingFileAppender">
<param name="File" value="C:\\Support\Logs\\logs.log" />
<param name="AppendToFile" value="true" />
<param name="RollingStyle" value="Size" />
<param name="MaxSizeRollBackups" value="10" />
<param name="MaximumFileSize" value="1024KB" />
<param name="StaticLogFileName" value="true" />
<lockingModel type="log4net.Appender.FileAppender+MinimalLock" />
<layout type="log4net.Layout.PatternLayout, log4net, Version=1.2.10.0, Culture=neutral, PublicKeyToken=1b44e1d426115821">
<param name="ConversionPattern" value="%date{MM-dd-yyyy HH:mm:ss} [%-5level] [%identity] - %message %newline" />
</layout>
</appender>
</log4net>
#4 I have a folder created C:\Support\Logs
#5 The log4net.config file is located in C:\DEV\App\source\App.Web\log4net.config
6)控制器,其中我想記錄字符串
These 2 values getting in the controller correctly
using log4net;
using log4net.Config;
using System.Configuration;
namespace My.Controllers
{
public class TestController : MyBaseController
{
private static readonly ILog _log = LogManager.GetLogger("MyLogger");
private static readonly string _log4netConfigFilename = ConfigurationManager.AppSettings["Log4NetConfigFilename"];
private static readonly string _log4netConfigFilePath = ConfigurationManager.AppSettings["Log4NetConfigFilePath"];
[HttpGet]
public ActionResult Index()
{
if (_log.IsDebugEnabled) <-- ALWAYS FALSE
_log.DebugFormat("Processing Index() view"); <-- NEVER GETS WRITTEN
var model = new MyModel();
return View(model);
}
}
}