九九热最新网址,777奇米四色米奇影院在线播放,国产精品18久久久久久久久久,中文有码视频,亚洲一区在线免费观看,国产91精品在线,婷婷丁香六月天

歡迎來到裝配圖網(wǎng)! | 幫助中心 裝配圖網(wǎng)zhuangpeitu.com!
裝配圖網(wǎng)
ImageVerifierCode 換一換
首頁 裝配圖網(wǎng) > 資源分類 > DOCX文檔下載  

Log4Net日志配置[附帶源碼下載]概要

  • 資源ID:24857246       資源大?。?span id="24d9guoke414" class="font-tahoma">58.47KB        全文頁數(shù):14頁
  • 資源格式: DOCX        下載積分:0積分
快捷下載 游客一鍵下載
會員登錄下載
微信登錄下載
三方登錄下載: 微信開放平臺登錄 支付寶登錄   QQ登錄   微博登錄  
二維碼
微信掃一掃登錄
下載資源需要0積分
郵箱/手機(jī):
溫馨提示:
用戶名和密碼都是您填寫的郵箱或者手機(jī)號,方便查詢和重復(fù)下載(系統(tǒng)自動生成)
支付說明:
本站最低充值0.01積分,下載本資源后余額將會存入您的賬戶,您可在我的個(gè)人中心查看。
驗(yàn)證碼:   換一換

 
賬號:
密碼:
驗(yàn)證碼:   換一換
  忘記密碼?
    
友情提示
2、PDF文件下載后,可能會被瀏覽器默認(rèn)打開,此種情況可以點(diǎn)擊瀏覽器菜單,保存網(wǎng)頁到桌面,就可以正常下載了。
3、本站不支持迅雷下載,請使用電腦自帶的IE瀏覽器,或者360瀏覽器、谷歌瀏覽器下載即可。
4、本站資源下載后的文檔和圖紙-無水印,預(yù)覽文檔經(jīng)過壓縮,下載后原文更清晰。
5、試題試卷類文檔,如果標(biāo)題沒有明確說明有答案則都視為沒有答案,請知曉。

Log4Net日志配置[附帶源碼下載]概要

Log4Net日志配置附帶源碼下載這篇文章主要介紹了 Log4Net日志配置附帶源碼下載需要的朋友可以參考下 前述園子里有許多人對10g4net這款開源的日志記錄控件有很多介紹。在這里個(gè)人再做一次 總結(jié),希望對以后有所幫助,需要的時(shí)候可以直接使用,減少查閱資料的時(shí)間。 利用10g4net可以方便地將日志信息記錄到文件、控制臺、Windows事件日志和數(shù)據(jù)庫,并且我們還可以記載控制要記載的日志級別,可以記載的日志類別包括:FATAL(致命錯(cuò)誤)、ERROR(一般錯(cuò)誤)、WARN (警告)、INFO (一般信息)、DEBUG (調(diào)試信息)。10g4net有四種主要的 組件,分別是Logger (記錄器),Repository (庫),Appender (附著器)以及Layout (布局). 準(zhǔn)備工作:1.下載 log4net.dll 下載地址http:/logging.apache.org/log4net/download_log4net.cgi 下載文件:log4net-1213-bin-newkey.zip。解壓選擇對應(yīng)的 net版本找到log4net.dll。彘一交翩 MlbEi IMn Hftihn郵”5aA,坤 取 叔帙Gill jjl Hjj 10,隆III 一1一期2.在項(xiàng)目中引用log4net.dll。解決方案資源苣理器嗟家望詼案變源皆理髓m 嶙;突方案”仕個(gè)項(xiàng)目)圓 Project.Log4.NetD ,Propertfes向引用W Iog4net" Mkrosoft.CSharp System實(shí)例代碼準(zhǔn)備工作完成后我們來看下實(shí)例代碼,首先在項(xiàng)目中創(chuàng)建一個(gè)文件夾LogConfig。把有關(guān)10g4net的一些配置文件和類都放在這個(gè)文件夾里面。WEB網(wǎng)站為例,在項(xiàng)目 LogCon的文件夾中創(chuàng)建 Log4Net.config配置文件。123<?xml version="1.0" encoding="utf-8"?>configuration<configSections>567891011121314151617181920212223242526272829303132333435363738394041424344454647<!-添加自定義節(jié)點(diǎn):log4net type:解析類名,程序集名(log4net.dll)->section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/> </configSections><log4net><!-定義輸出到文件中-><appender name="Log4Net_INFO" type="log4net.Appender.RollingFileAppender"><!-定義文件存放位置->file value="C:/log4net/"/><!-是否追加到文件,默認(rèn)為true ,通常無需設(shè)置-><appendToFile value="true"/>RollingStyle value="Date"/><!-日期的格式,每天換一個(gè)文件記錄,如不設(shè)置則永遠(yuǎn)只記錄一天的日志,需設(shè)置 ->DatePattern value="INFO_yyyyMMdd".log"" /><!-日志文件名是否為靜態(tài)->StaticLogFileName value="false"/><!-多線程時(shí)采用最小鎖定->lockingModel type="log4net.Appender.FileAppender+MinimalLock" />!-布局(向用戶顯示最后經(jīng)過格式化的輸出信息)->layout type="log4net.Layout.PatternLayout"><!-%m(message):輸出的日志消息,如ILog.Debug(輸融的一條消息%n(new line):換行%d(datetime):輸出當(dāng)前語句運(yùn)行的時(shí)刻%r(run time):輸出程序從運(yùn)行到執(zhí)行到當(dāng)前語句時(shí)消耗的毫秒數(shù)%t(thread id):當(dāng)前語句所在的線程ID%p(priority):日志的當(dāng)前優(yōu)先級別,即 DEBUG INFO、WARN-等%c(class)當(dāng)前日志對象的名稱,例如:%L:輸出語句所在的行號%F:輸出語句所在的文件名%啜字:表示該項(xiàng)的最小長度,如果不夠,則用空格填充-> <Header value="Header"/><Footer value="Footer"/><!-正文->ConversionPattern value="記錄時(shí)間: %date 線程 ID:%thread日志級別: %-5level 出 錯(cuò)類:%logger property:%propertyNDC- 錯(cuò)誤描述:message%newline" /> </layout> </appender><appender name="Log4Net_ERROR" type="log4net.Appender.RollingFileAppender"><file value="C:/10g4net/"/>appendToFile value="true"/>48 <RollingStyle value="Date"/>49 <DatePattern value="ERROR_yyyyMMdd".log"" />50 <StaticLogFileName value="false"/>51 <lockingModel type="log4net.Appender.FileAppender+MinimalLock" />52 layout type="log4net.Layout.PatternLayout">53 Header value="Header54"/>55 Footer value="Footer56"/>57<!-正文->58 ConversionPattern value="記錄時(shí)間: date 線程 ID:%thread日志級別: -5level 出59 錯(cuò)類:%logger property:%propertyNDC- 錯(cuò)誤描述:%message%newline" />60 /layout61 /appender>62 <root>63 level value="DEBUG"/>64 appender-ref ref="Log4Net_ERROR" />65 level value="INFO"/>66 appender-ref ref="Log4Net_INFO" />67 /root>68 /log4net>69 /configuration>70717273747576配置文件寫完后我們在來寫一個(gè)Helper類。同樣在項(xiàng)目中創(chuàng)建一個(gè)名為LogHelper.cs的類文1 using log4net;2 using System;3 using System.Collections.Concurrent;4 using System.Collections.Generic;5 /指定log4net使用的config文件來讀取配置信息6 assembly: log4net.Config.XmlConfigurator(ConfigFile = "LogConfigLog4Net.config",7 Watch = true)8 namespace Project.Log4.Net.LogConfig9 10 /summary>11 /日志幫助類12/summary>13public class LogHelper14151617181920212223242526272829303132333435363738394041424344454647484950515253545556newprivate static readonly ConcurrentDictionary<Type, ILog> _loggers ConcurrentDictionary<Type, ILog>();/ <summary>/獲取記錄器/ </summary>/ <param name="source"></param>/ <returns></returns>private static ILog GetLogger(Type source)if (_loggers.ContainsKey(source)return _loggerssource; elseILog logger = LogManager.GetLogger(source);_loggers.TryAdd(source, logger); return logger; /* Log a message object */ / <summary> /調(diào)試信息 / </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Debug(object source, string message) Debug(source.GetType(), message);/ <summary>/調(diào)試信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="ps"></param>public static void Debug(object source, string message, params object口 ps) Debug(source.GetType(), string.Format(message, ps);/ <summary>/調(diào)試信息57/ </summary>585960616263646566676869707172737475767778798081828384858687888990919293949596979899100/ <param name="source"></param>/ <param name="message"></param>public static void Debug(Type source, string message)ILog logger = GetLogger(source);if (logger.IsDebugEnabled)logger.Debug(message);/ <summary>/關(guān)鍵信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Info(object source, object message)Info(source.GetType(), message);/ <summary>/關(guān)鍵信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Info(Type source, object message)ILog logger = GetLogger(source);if (logger.IsInfoEnabled)logger.Info(message);/ <summary>/警告信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Warn(object source, object message) Warn(source.GetType(), message);/ <summary>/警告信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Warn(Type source, object message)102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144101ILog logger = GetLogger(source);if (logger.IsWarnEnabled)logger.Warn(message);/ <summary>/錯(cuò)誤信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Error(object source, object message)Error(source.GetType(), message);/ <summary>/錯(cuò)誤信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Error(Type source, object message)ILog logger = GetLogger(source);if (logger.IsErrorEnabled)logger.Error(message);/ <summary>/失敗信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Fatal(object source, object message)Fatal(source.GetType(), message);/ <summary>/失敗信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>public static void Fatal(Type source, object message)ILog logger = GetLogger(source);if (logger.IsFatalEnabled)logger.Fatal(message);145 /* Log a message object and exception */ <summary>/調(diào)試信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Debug(object source, object message, Exception exception) Debug(source.GetType(), message, exception);/ <summary>/調(diào)試信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Debug(Type source, object message, Exception exception)GetLogger(source).Debug(message, exception);/ <summary>/關(guān)鍵信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Info(object source, object message, Exception exception)Info(source.GetType(), message, exception);/ <summary>/關(guān)鍵信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Info(Type source, object message, Exception exception)GetLogger(source).Info(message, exception);/ <summary>146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188/警告信息189/ </summary>190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Warn(object source, object message, Exception exception) Warn(source.GetType(), message, exception);/ <summary>/警告信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Warn(Type source, object message, Exception exception)GetLogger(source).Warn(message, exception);/ <summary>/錯(cuò)誤信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Error(object source, object message, Exception exception)Error(source.GetType(), message, exception);/ <summary>/錯(cuò)誤信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Error(Type source, object message, Exception exception)GetLogger(source).Error(message, exception);/ <summary>/失敗信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272233public static void Fatal(object source, object message, Exception exception)Fatal(source.GetType(), message, exception);/ <summary>/失敗信息/ </summary>/ <param name="source"></param>/ <param name="message"></param>/ <param name="exception"></param>public static void Fatal(Type source, object message, Exception exception) GetLogger(source).Fatal(message, exception);配置和Helper類都有了 .現(xiàn)在來看看調(diào)用方法。在項(xiàng)目中創(chuàng)建一個(gè) index.aspx頁面LogHelper.Debug(this, "Debug");LogHelper.Error(this, "Error");3 LogHelper.Fatal(this, "Fatal");4 LogHelper.Info(this, "Info");5 LogHelper.Warn(this, "Warn");日志生成格式每天一個(gè)文件:Download Apache log4net?Apache log4net is distributed under the Apache License, version 2.0.Starting with log4net 1.2.11 log4net is available as source only or binary only release.Users who download the ZIP files to Windows may need to unblock the archive (right click on the ZIP and press the "Unblock" button) before extracting it.Using a MirrorWe recommend you use a mirror to download our release builds, but you must verify the integrity of the downloaded files using signatures downloaded from our main distribution directories. Recent releases (48 hours) may not yet be available from the mirrors.You are currently using If you encounter a problem with this mirror, please select another mirror. If all mirrors are failing, there are backup mirrors (at the end of the mirrors list) that should be available.Other mirrors:ChangeThe KEYS link links to the code signing keys used to sign the product. The PGP link downloads the OpenPGP compatible signature from our main site. The MD5 link downloads the checksum from the main site.log4net 1.2.15Source10g4net-1215-src.zip md5 pgpBinariesThere are two different binary releases, oldkey and newkey. Both contain assemblies built for most supported platforms and have been built from the same code base, they only differ in the strong name key used to sign the assemblies.See the FAQ for background. We recommend you use the assemblies signed with the "new" key whenever possible.10g4net-1215-bin-newkey.zipmd5 pgplog4net-1215-bin-oldkey.zip md5 pgpArchivesRelease 1.2.11 and all more recent releases are available from the Apache Software Foundations distribution archive.The 1.2.10 and 1.2.9 releases have been created while log4net was still undergoing incubation and those releases are available from the distribution archive for the Incubator project.Previous releases of log4net are available from the SourceForge Project Site.Verify ReleasesIt is essential that you verify the integrity of the downloaded files using the PGP signature or MD5 checksums. The checksums are not as strong indicators as the PGP signature.Please read Verifying Apache HTTP Server Releases for more information on why you should verify our releases. The PGP keys used to sign our distributions are part of the KEYS file.計(jì)算機(jī)本地遨盅(C:) Iog4net I J"13 一 斶意看(V)工具E幫助(H)英聒羽證間的位置ERROR_20150402.log| 502字元二(N10_20150402.logI 502字方- -k lN30_20150403.log!| 文本文檔II 20字節(jié)ERROR_20150403.tog 文本文檔I 542 字EtN10_20150403Jog義本文檔 2。字節(jié)lN60_20150403.log1。李三包含至瞬中,共享, 刻錄參數(shù)說明Log4Net.config是配置日志輸出參數(shù)文件。在這個(gè)文件中可以到看很多配置節(jié)點(diǎn),大體可以 分為二個(gè)大類 <configSections>.</configSections> 和 <log4net>.</log4net> 。我們來看看這 些節(jié)點(diǎn)都是啥意思。1 : <configSections>.</configSections>:申明自定義節(jié)點(diǎn)10g4net解析的類名和程序集名(log4net.dll)。2: <log4net>.</log4net>:使用10g4net的配置信息都在這里設(shè)置。來重點(diǎn)看看都有那些設(shè)置 信息,這個(gè)大節(jié)點(diǎn)整體也可以分為二類。2.1 :定義輸出信息設(shè)置節(jié)點(diǎn) <appender></appender> 。2.2 :定義日志的輸出媒介 <root></root> 。配置的總體結(jié)構(gòu)就是這樣,下面來看一些詳細(xì)內(nèi)容。appender:決定日志輸出的方式(可設(shè)置多個(gè)節(jié)點(diǎn),如對INFO, ERRO曲設(shè)置不同的輸出方式)。主要包括已下幾種:1 AnsiColorTerminalAppender:在ANSI窗口終端寫下高亮度的日志事件。2 AspNetTraceAppender:能用中Trace的方式查看記錄的日志。3 BufferingForwardingAppender:在輸出到子Appenders之前先緩存日志事件。4 ConsoleAppender:將日志輸出到控制臺。5 EventLogAppender:4各日志寫至U Windows Event Log.6 FileAppender:將日志寫到文件中。7 LocalSyslogAppender:將日志寫至ij local syslog service (僅用于 UNIX 環(huán)境下).8 MemoryAppender:將日志存到內(nèi)存緩沖區(qū)。9 NetSendAppender:將日志輸出到 Windows Messenger service.這些日志信息將在用戶終端的 對話框中顯示。10 RemoteSyslogAppender:通過 UDP 網(wǎng)絡(luò)協(xié)議將日志寫到 Remote syslog serviceo11 RemotingAppender:通過.NET Remoting將日志寫到遠(yuǎn)程接收端。12 RollingFileAppender:將日志以回滾文件的形式寫到文件中。(實(shí)例代碼中使用的是此類型)13 SmtpAppender:將日志寫到郵件中。14 TraceAppender:將日志寫到.NET trace 系統(tǒng)。15 UdpAppender:將日志 connectionless UDP datagrams 的形式送到遠(yuǎn)程宿主或以UdpClient 的形式廣播。從上面提供的方式中可以看出能輸出文件、控制臺、Windows事件日志和數(shù)據(jù)庫。這個(gè)可根據(jù)實(shí)際情況選擇。復(fù)制代碼代碼如下:<appender name="Log4Net_INFO" type="log4net.Appender.RollingFileAppender">.< /appender>這里配置的name ("Log4Net_INFO")會在定義日志的輸出媒介中使用到。name可任意設(shè)置。在appender節(jié)點(diǎn)中還會配置一些文件存放的地址,日志個(gè)數(shù)等信息。這些在實(shí)例代碼中都 在體現(xiàn),這里不做說明。我們在來看看日志最后輸出呈現(xiàn)的布局設(shè)置信息。1 layout type="log4net.Layout.PatternLayout">2<!-頭->3Header value="Header"/>4<!-腳注->5<Footer value="Footer"/>6<!-正文->7ConversionPattern value="%d %t %-5p %c %x - %m%n" />8 </layout>這里配置的信息最終是日志打印出來的樣式。我們可以看到這里可以設(shè)置內(nèi)容頭Header和尾Footer。正文ConversionPattern。在正文中有出現(xiàn)有%d %t這些都是啥意思了表示什么。這里有一個(gè)對照表可提供參考:%m(message)輸出的日志消息,如ILog.Debug()輸出的一條消息%n(new line):換行%d(datetime):輸出當(dāng)前語句運(yùn)行的時(shí)刻%r(run time):輸出程序從運(yùn)行到執(zhí)行到當(dāng)前語句時(shí)消耗的毫秒數(shù)%t(thread id):當(dāng)前語句所在的線程 ID%p(priority):日志的當(dāng)前優(yōu)先級別,即 DEBUG INF。WARN等%c(class)當(dāng)前日志對象的名稱,例如:%L:輸出語句所在的行號%F:輸出語句所在的文件名%啜字:表示該項(xiàng)的最小長度,如果不夠,則用空格填充配置的基本也就這些。下就是root的配置說明。root:對設(shè)置輸出的方式進(jìn)行指定。123456789<root><!-批定DEBUG輸出的文件形式記錄日志 -><level value="DEBUG"/><appender-ref ref="Log4Net_ERROR" /><!-批定INFO輸出的文件形式記錄日志-><level value="INFO"/><appender-ref ref="Log4Net_INFO" /></root>控制級別,由低到高:ALL|DEBUG|INFO|WARN|ERROR|FATAL|OFF比如定義級別為INFO,則INFO級別向下的級別,比如 DEBUG日志將不會被記錄 如果沒有定義LEVEL的值,則缺省為DEBUG

注意事項(xiàng)

本文(Log4Net日志配置[附帶源碼下載]概要)為本站會員(簡****9)主動上傳,裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。 若此文所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng)(點(diǎn)擊聯(lián)系客服),我們立即給予刪除!

溫馨提示:如果因?yàn)榫W(wǎng)速或其他原因下載失敗請重新下載,重復(fù)下載不扣分。




關(guān)于我們 - 網(wǎng)站聲明 - 網(wǎng)站地圖 - 資源地圖 - 友情鏈接 - 網(wǎng)站客服 - 聯(lián)系我們

copyright@ 2023-2025  zhuangpeitu.com 裝配圖網(wǎng)版權(quán)所有   聯(lián)系電話:18123376007

備案號:ICP2024067431-1 川公網(wǎng)安備51140202000466號


本站為文檔C2C交易模式,即用戶上傳的文檔直接被用戶下載,本站只是中間服務(wù)平臺,本站所有文檔下載所得的收益歸上傳人(含作者)所有。裝配圖網(wǎng)僅提供信息存儲空間,僅對用戶上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對上載內(nèi)容本身不做任何修改或編輯。若文檔所含內(nèi)容侵犯了您的版權(quán)或隱私,請立即通知裝配圖網(wǎng),我們立即給予刪除!