2013-04-14 4 views

答えて

4

、ありがとうございました。それはNuGet経由で利用可能です。

Elmahには元々意図したロガーに加えて例外、エラー、致命的な呼び出しが記録されます。他のすべてのログタイプでは、元のロガーのみが使用されます。

すでにlog4netのを使用している場合は、あなただけの任意のASPにELMAHを追加調査することができ、既存のログ上でラップしたくないのであれば、あなたはちょうどこの

ElmahLogFactory factory = new ElmahLogFactory(new Log4NetFactory()); 

ようELMAHを設定することができます。 NET Webサイト。 ServiceStackを使用しているだけでは機能しない理由はありません。

3
using ServiceStack.Logging; 
using ServiceStack.Logging.Elmah; 
using ServiceStack.Logging.NLogger; 

public AppHost() 
     : base(
      "description", 
      typeof(MyService).Assembly) 
    { 
     LogManager.LogFactory = new ElmahLogFactory(new NLogFactory()); 
    } 

    public override void Configure(Container container) 
    { 
     this.ServiceExceptionHandler += (request, exception) => 
      { 
       // log your exceptions here 
       HttpContext context = HttpContext.Current; 
       ErrorLog.GetDefault(context).Log(new Error(exception, context)); 

       // call default exception handler or prepare your own custom response 
       return DtoUtils.HandleException(this, request, exception); 
      }; 

     // rest of your config 
    } 
} 

ここで、あなたのServiceStackエラーがElmahに表示されます(あなたがweb.configなどをセットアップしたと仮定します)。

+0

ただ、明確にするためには、上記の例外のための単一のエントリポイントを使用している答えは...します。https:// githubの

ElmahLogFactory

は、例えばServiceStack APPHOSTを初期化する前に、あなたのGlobal.asaxに設定することができます.com/ServiceStack/ServiceStack/wiki /エラー処理 – Darren

2

実際にkampsj答えはGavinsよりも優れています.Gavinsは明示的なelmah loggerを呼び出してelmahに二重ログを記録し、デフォルトのサービス・エラー処理を行います。

ElmahLogFactory factory = new ElmahLogFactory(); 

を...しかし、あなた:

だから本当に必要なのは、この(あなたがELMAHとラップNLogにしたいと仮定の下)である

public class YourAppHost : AppHostBase 
{ 
    public YourAppHost() //Tell ServiceStack the name and where to find your web services 
     : base("YourAppName", typeof(YourService).Assembly) 
    { 
     LogManager.LogFactory = new ElmahLogFactory(new NLogFactory()); 
    } 

    //...just normal stuff... 
} 

あなたは上記の本を持っている可能性がありDebugやWarnのようなエラーのないロギングのために別のタイプのロガーをラップする必要があります。

0

configuring Elmahこのセクションと一緒に構成ServiceStackとELMAHの作業例えばLogging.Elmah UseCase

public class Global : System.Web.HttpApplication 
{ 
    protected void Application_Start(object sender, EventArgs e) 
    { 
     var debugMessagesLog = new ConsoleLogFactory(); 
     LogManager.LogFactory = new ElmahLogFactory(debugMessagesLog, this); 
     new AppHost().Init(); 
    } 
} 
関連する問題