Without seeing my source code, I can only make assumptions, but I think Elmah stops registering because you get an exception. This can happen because the property Sessionis null. A session is available only after the event PostAcquireRequestState, so you cannot count on the fact that this property is always available.
I tried this myself and wrote a method like this:
private static Dictionary<string, object> CopySession(HttpSessionState session)
{
if (session == null || session.Count == 0)
return null;
Dictionary<string, object> copy = new Dictionary<string, object>(session.Count);
foreach (var key in session.Keys)
{
string name = key.ToString();
copy.Add(name, session[name]);
}
return copy;
}
I call this method in the constructor of the Error class as follows:
_session = CopySession(context.Session);
(immediately after copying the server variables and other context contents. You may need to change the implementation IClonableto copy the field _session).
, . SqlErrorLog, ErrorLog: , , .