How can I determine programmatically whether or not ELMAH is enabled?
+1
A:
Because:
ELMAH can be dynamically added to a running ASP.NET web application, or even all ASP.NET web applications on a machine, without any need for re-compilation or re-deployment.
you should not need to detect whether it is present. Just write your logging code as if it was present, and if it's not, nothing will be logged.
Of interest?: How to get ELMAH to work with ASP.NET MVC [HandleError] attribute? (accepted answer is by ELMAH's author)
Mitch Wheat
2010-01-31 06:12:24
I need to show a link to elmah.axd. If it's disabled, I don't want to show the link?
lance
2010-01-31 06:16:08
Can you make a web request to elmah.axd and check the status code? Maybe do this once and store the results in the Application variable for future uses.
Greg
2010-02-01 17:42:34
@Greg: I was hoping to avoid that overhead. Your solution is what I've coded so far, as it's the best I could think of. I'm going to try looking through the loaded modules list, per Tadas' answer above.
lance
2010-02-02 14:36:21
+1
A:
You can enumerate all loaded modules (via HttpApplication.Modules) and if Elmah module exists, then Elmah is enabled:
foreach (var m in Application.Modules) {
if (m is Elmah.ErrorlogModule) {
// ...
}
}
Not sure. Haven't treed this.
Tadas
2010-02-02 09:45:49
I tried this, but Application.Modules wasn't available (it's been a while since I tried -- I might be remembering the details incorrectly, but I couldn't make it happen). Do you have actual code that you've used to do this?
lance
2010-03-05 15:40:47