I need some Elmah logging in the async task running on my web server. But when I try to register an error, it fails due to the HttpContext.
var httpContext = HttpContext.Current; Task.Factory.StartNew(() => { HttpContext.Current = httpContext; try { //Execute some code } catch (Exception ex) { //Generate some error for the user and log the error in Elmah try { ErrorLog.GetDefault(HttpContext.Current).Log(new Error(ex)); } catch(Exception ex) { } } });
To make progress in the task, I implemented some kind of polling mechanism. Currently, none of the errors are logged in Elmah, which makes them difficult to resolve.
Also, providing context as a parameter does not work.
This does not work. I get an ArgumentException saying that the expected value does not fall into the expected range. Using the following stacktrace command:
in System.Runtime.InteropServices.Marshal.ThrowExceptionForHRInternal (Int32 errorCode, IntPtr errorInfo) in System.Web.Hosting.IIS7WorkerRequest.GetServerVariableInternal (row name) in System.Web.HttpRequest.AddTerVer.arver.verververvalve.ververveverwerverveverwerverwerverwerverwerverwerwerwerwerver FillInServerVariablesCollection () in System.Web.HttpServerVarsCollection.Populate () in System.Web.HttpServerVarsCollection.Get (string name) in Elmah.ErrorLog.InferApplicationName (HttpContext context) in Elmah.ertextLeftrlfrtltext.rtleftextertext.rtleftextertext.rtlfer.errtltext.rtlf.textrleftpreference GetService (type serviceType) in Elmah.ServiceCenter.GetService (object context, type serviceType) in Elmah.ErrorLog.GetDefault (HttpContext context) in Bis.Utilities.Log.ElmahErrorLog.TryLogError (Exception \ exeption) D500: Documents \ Projecten \ Biobank \ Bis \ src \ Utilities \ Log \ ElmahErrorLog.cs: line 13
source share