OK, apparently related questions dont seem to address this directly. An exception reaches Elmah, maybe a repository cant reach a database, but then neither can Elmah reach that database. Even if they target different servers, maybe its a network problem.
Is there a way to configure fallback logs for Elmah for cases like this, e.g. a text file, message queue, email, sms, etc? If so, where do I start looking to do this, excpt for now the Elmah 开发者_StackOverflow社区source code.
I am usually not so concerned about that: If the DB is not running then my application is not running and I have no exceptions to log anyway. But if this is an issue for you then you could consider to use the XmlFileErrorLog
.
As far as I can tell you cannot use more then one log destination and there is nothing like a fallback. You could however configure email notifications, but then you would get all exceptions by email as well.
Here is quite a nice article about elmah.
I released a composite errorlog which address exactly this issue.
You can install it via Nuget or copy it from sources into your projects.
Basic usage from config file :
<configuration>
<configSections>
<sectionGroup name="elmah">
<section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
<section name="errorLog" requirePermission="false" type="Elmah.FallbackErrorLogSectionHandler, Elmah.FallbackErrorLog" />
<section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
<section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
</sectionGroup>
</configSections>
<elmah>
<errorLog type="Elmah.FallbackErrorLog, Elmah.FallbackErrorLog" >
<add type="Elmah.SqlErrorLog, Elmah" connectionStringName="DB_ELMAH" applicationName="Blog" />
<add type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data/Logs" />
<add type="Elmah.MemoryErrorLog, Elmah" size="30" />
</errorLog>
</elmah>
</configuration>
精彩评论