一,下载log4net.dll,在项目中添加引用
二,在站点根目录添加,配置文件(log4net.xml), <file value="logs/logfile.txt"/>配置了文件的输出路径,确认是否添加了文件夹和文件
三,在Global.asax文件中的Application_Start()方法的结尾处添加,读取Log的配置文件
XmlConfigurator.ConfigureAndWatch(new FileInfo(Server.MapPath("log4net.xml")));
在AssemblyInfo.cs添加,[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.xml", Watch = true)]
四,添加using log4net 执行调用输出
using System;using System.Collections.Generic;using System.Linq;using System.Web;using System.Web.Mvc;using Test.Models.View.HomeModel;using Test.Models.Entities;using log4net;namespace Test.Controllers{ public class HomeController : Controller { protected static readonly ILog Log = LogManager.GetLogger(typeof(MvcApplication)); public ActionResult test() { string cc = "111"; Log.FatalFormat("{0}", cc); return View(); } }}