Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I append the SQL ELMAH_Error.ErrorID to the ELMAH Error Email Subject?
    primarykey
    data
    text
    <p>I'm using ELMAH to log errors to a SQL database AND send an email. I'd like to append the ELMAH_Error.ErrorId to the subject of the ELMAH email.</p> <p>I'm saving the ErrorId ELMAH provides in the ElmahLog_Logged event into a session variable as I discovered in <a href="https://stackoverflow.com/q/7895271/178207">this question</a>. Atif Aziz himself commented on <a href="http://scottonwriting.net/sowblog/archive/2011/01/06/customizing-elmah-s-error-emails.aspx" rel="nofollow noreferrer">this blog post</a> the following information regarding this:</p> <blockquote> <p>If one does want a crack at the logged Error during mailing, one would have to pick it up in the ErrorLogModule.Logged event. This could be handy, for example, to push the Id of the logged error into the mail. To do that, you'd stash away the Id from the Logged event into the HttpContext and use it later in the Mailing event. For this to work, the modules would have be registered such that the Mailing event occurs after the Logged event.</p> </blockquote> <p>I thought that since the httpModules are added with ErrorLog first and ErrorMail second, that this would achieve registering the Mailing event after the Logged event. I suppose that's talking about order of the events, not the order the Modules are applied in.</p> <p><strong>How do you register the event order of HttpModules?</strong></p> <p>I have tried the code below to no avail. The code below prevents the email from sending, but the error is still logged to the SQL table. </p> <h2>Web.Config:</h2> <pre><code>&lt;system.web&gt; &lt;httpModules&gt; &lt;add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" /&gt; &lt;add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /&gt; &lt;add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" /&gt; &lt;/httpModules&gt; &lt;httpHandlers&gt; &lt;add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" /&gt; &lt;/httpHandlers&gt; &lt;/system.web&gt; </code></pre> <p>... and ...</p> <pre><code>&lt;system.webServer&gt; &lt;validation validateIntegratedModeConfiguration="false" /&gt; &lt;modules&gt; &lt;add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" preCondition="managedHandler" /&gt; &lt;add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" preCondition="managedHandler" /&gt; &lt;add name="ErrorFilter" type="Elmah.ErrorFilterModule, Elmah" preCondition="managedHandler" /&gt; &lt;/modules&gt; &lt;handlers&gt; &lt;add name="Elmah" path="elmah.axd" verb="POST,GET,HEAD" type="Elmah.ErrorLogPageFactory, Elmah" preCondition="integratedMode" /&gt; &lt;/handlers&gt; &lt;/system.webServer&gt; </code></pre> <p>And of course the and are properly configured (I installed via NuGet).</p> <h2>Global.asax.cs:</h2> <pre><code>protected void ErrorLog_Logged(object sender, ErrorLoggedEventArgs args) { Session["ElmahId"] = args.Entry.Id; } protected void ErrorMail_Mailing(object sender, ErrorMailEventArgs e) { var elmahErrorId = Session["ElmahId"].ToString(); e.Mail.Subject = String.Format("{0}, see ELMAH_Error.ErrorID = {1}", e.Mail.Subject, elmahErrorId); } </code></pre> <p>If I change the ErrorMail_Mailing event code in global.asax.cs to the following code, I receive the Email with the subject specified in the ErrorMail_Mailing event code as I should. I've even tried to just put Session.SessionID in the subject and that kills the email functionality. <strong>This makes me think that the ErrorMail_Mailing event does not have Session access. Is this correct?</strong></p> <pre><code>protected void ErrorMail_Mailing(object sender, ErrorMailEventArgs e) { e.Mail.Subject = "I changed the subject in global.asax"; } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload