在控制台应用程序中使用ELMAH [英] Using ELMAH in a console application

查看:129
本文介绍了在控制台应用程序中使用ELMAH的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚开始使用ELMAH,并是一个球迷。我的团队支持大量的网络应用程序,我特别兴奋,ELMAH可以让我们节省了例外,从每个应用程序相同的MS SQL数据库表。

I just started using ELMAH and am a fan. My team supports a large number of web applications and I'm particularly excited that ELMAH lets us save exceptions from each application to the same MS SQL database table.

我们也支持一些控制台,DLL和桌面应用程序。是否有可能使用ELMAH DLL来登录这些应用程序的例外是相同的位置?

We also support a few console, DLL and desktop applications. Is it possible to use the ELMAH DLL to log exceptions in these apps to that same location?

推荐答案

我们有完全相同这里同样的情况。我们所有的Web应用程序运行ELMAH。他们中很少有基于控制台的调度。

We have exactly the same situation here. Running ELMAH for all our web applications. A few of them have console based schedulers.

通源$ C ​​$ C做一些挖后,以下code似乎工作:

After doing some digging through the source code, the following code seems to work:

            ErrorLog errorLog = ErrorLog.GetDefault(null);
            errorLog.ApplicationName = "/LM/W3SVC/1/ROOT/AppName";
            errorLog.Log(new Error(ex));

与上面的唯一真正的问题是,你需要的地方保持应用程序的名字在你的配置才能够看到的ELMAH.axd浏览器中的条目。

The only real problem with the above is that you need to keep the application name somewhere in your config to be able to see the entries on the ELMAH.axd viewer.

因此​​,在我们一般的错误处理code,我们做的:

So in our generic error handling code we do:

        if (HttpContext.Current != null)
            ErrorSignal.FromCurrentContext().Raise(ex);
        else
        {
            ErrorLog errorLog = ErrorLog.GetDefault(null);
            errorLog.ApplicationName = ErrorHandling.Application;
            errorLog.Log(new Error(ex));
        }

这篇关于在控制台应用程序中使用ELMAH的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆