|
1 拷貝 log4net.dll 到源代碼根目錄 2 在項目中添加對log4net.dll 的引用 3 修改程序配置文件 添加兩部分內容: (1) 在 <configSections> </configSections>中添加一行 <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler,log4net" /> (2) 在<configuration></configuration>添加一段 <log4net> 說明:上面的配置里的update.log是要記錄到的文件名 其他參數的意義請參考手冊 4 在程序啟動時讀取log4net的配置文件 如果是cs程序 在根目錄的Program.cs中 在mani方法中添加 log4net.Config.XmlConfigurator.Configure(); 如果是bs程序 在根目錄的Global.asax.cs 中的Application_Start方法中添加 log4net.Config.XmlConfigurator.Configure(); 5 然后 可在在程序中使用log4net功能了 使用方法如下: log4net.ILog log = log4net.LogManager.GetLogger("AppLogger"); //獲取一個日志記錄器 6 如果使用獨立的配置文件,需要在main方法里改
log4net.Config.XmlConfigurator.Configure(new FileInfo(@"c:/a/log4net.config"));
注意此處,如果寫成相對路徑,將無法導入
|
|
|