2009-07-19 7 views

答えて

0

今はかなり年ですが、thisスレッドでは、あなたが探していることについて話し合っています。

+3

死んだが、利用可能なリンクの[インターネットアーカイブ]に(https://web.archive.org/web/20130528024223/http://www.l4ndash.com/Log4NetMailArchive/tabid/70/forumid/1/postid/14714/view/topic/Default.aspx) – stuartd

+0

数年後...両方のリンクが死んでいる。リンクの腐敗のためによろしく! – WernerCD

13

をここで概説として、これは拡張メソッドで行うことができますいくつかの拡張機能を追加する http://rageshkrishna.com/2011/01/21/AddingCustomLogLevelsToLog4net.aspx

新しいログレベルの を使用すると簡単に死んでしまいます。

public static class SecurityExtensions 
{ 
    static readonly log4net.Core.Level authLevel = new log4net.Core.Level(50000, "Auth"); 

    public static void Auth(this ILog log, string message) 
    { 
     log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, 
      authLevel, message, null); 
    } 

    public static void AuthFormat(this ILog log, string message, params object[] args) 
    { 
     string formattedMessage = string.Format(message, args); 
     log.Logger.Log(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType, 
      authLevel, formattedMessage, null); 
    } 

} 

そして、それはそれだ - 今、私はこのような 上のILogの任意のインスタンスを私の新しい「認証」ログレベルを使用して起動することができます。

SecurityLogger.AuthFormat("User logged in with id {0} from IP address {1}", id, Request.UserHostAddress); 
+3

単なるリンクではなく、この質問に対する唯一の回答でありがとうございます。 – Shelby115

関連する問題

 関連する問題