有什么办法通过编程设置ELMAH应用程序的名称? [英] Is there any way to programmatically set the application name in Elmah?

查看:174
本文介绍了有什么办法通过编程设置ELMAH应用程序的名称?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要根据我使用Visual Studio中什么样的配置来改变应用程序的名称。例如,如果我在调试配置的时候,我想应用程序名称显示为在Elmah_Error表中的应用领域App_Debug。有没有人有这样的经验吗?还是有另一种方式来做到这一点?

I need to change the app name based on what configuration I'm using in Visual Studio. For example, if I'm in Debug configuration, I want the app name to show as 'App_Debug' in the Application field in the Elmah_Error table. Does anyone have any experience with this? Or is there another way to do it?

推荐答案

在默认情况下,ELMAH使用的应用程序池的应用程序GUID为默认应用程序名称。它使用这个作为重点来识别Elmah_Error表中的错误,当你看这是通过它的HTTP模块创建的Web界面。

By default, Elmah uses the AppPool's application GUID as the default application name. It uses this as the key to identify the errors in the Elmah_Error table when you look at the web interface that's created through it's HTTP Module.

我的任务是在今年早些时候去探索这个选项为我的公司。我无法找到一个方法,默认情况下操纵这一点,因为ELMAH从 HttpRuntime.AppDomainAppId 在ErrorLog.cs拉文件的应用程序名称。您可以通过任何你想要的按键操作它;然而,这是程序池的GUID

I was tasked to explore this option for my company earlier this year. I couldn't find a way to manipulate this by default since Elmah pulls the application name from HttpRuntime.AppDomainAppId in the ErrorLog.cs file. You could manipulate it by whatever key you want; however, that is the AppPool's GUID.

随着中说,我是能够操纵ErrorLog.cs文件转成ELMAH一个可调用的框架,而不是基于一个处理程序,并允许我设定的应用程序名称。最后我什么事做了修改ErrorLog.cs以包括让我设置如下名称的属性:

With that said, I was able to manipulate the ErrorLog.cs file to turn Elmah into a callable framework instead of a handler based one and allow for me set the ApplicationName. What I ended up doing was modifying ErrorLog.cs to include a property that allowed me to set the name as below:

public virtual string ApplicationName
        {
            get 
            {
                if (_applicationName == null) {  _applicationName = HttpRuntime.AppDomainAppId; }
                return _applicationName;
            }
            set { _applicationName = value; }
        }

什么你可能需要做的是不同的调整这一点,并没有设置应用​​程序名称为 HttpRuntime.AppDomainAppId 但是,相反,值从web.config拉动。总而言之,这是可能的。我做的方式,增强了 ErrorLog.Log(前)方法,所以我可以使用ELMAH已经超越Web应用程序的调用框架。回头看我希望我做的应用程序/ web.config中的方法来代替。

What you will probably need to do is adjust this differently and set the ApplicationName not to HttpRuntime.AppDomainAppId but, instead, a value pulled from the web.config. All in all, it's possible. The way I did it enhanced the ErrorLog.Log(ex) method so I could use Elmah has a callable framework beyond web applications. Looking back I wish I did the app/web.config approach instead.

一件事ELMAH改变应用程序的名称时,要牢记。产生的/elmah/default.aspx接口HTTP处理程序将不再工作。我仍然在试图找到时间来绕绕回这样的;但是,您可能需要考虑实施的时候创建一个自定义的界面。

One thing to keep in mind when changing the application name in Elmah. The http handler that generates the /elmah/default.aspx interface will no longer work. I'm still trying to find time to circle back around to such; however, you may need to look into creating a custom interface when implementing.

这篇关于有什么办法通过编程设置ELMAH应用程序的名称?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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