c# - Casting ExceptionLoggerContext to HttpContext -


i've written exception logger implementing system.web.http.exceptionhandling.exceptionlogger class.

we have generic exception logging services, 1 of implementations raygun. uses httpcontext.current can seen here: https://github.com/mindscapehq/raygun4net/blob/master/mindscape.raygun4net/raygunclient.cs on line 337.

public override void log(exceptionloggercontext context) {     httpcontext.current = ...;     exceptionservice.logexception(context.exception);             } 

is possible convert / cast: system.web.http.exceptionhandling.exceptionloggercontext system.web.httpcontext?

you can following

    public override void log(exceptionloggercontext context)     {         httpcontext httpcontext = gethttpcontext(context.request);         exceptionservice.logexception(context.exception);     }      private static httpcontext gethttpcontext(httprequestmessage request)     {         httpcontextbase contextbase = gethttpcontextbase(request);         if (contextbase == null)         {             return null;         }          return contextbase.applicationinstance.context;     }      private static httpcontextbase gethttpcontextbase(httprequestmessage request)     {         if (request == null)         {             return null;         }          object value;          if (!request.properties.trygetvalue("ms_httpcontext", out value))         {             return null;         }         return value httpcontextbase;     } 

copied here


Comments

Popular posts from this blog

php - How to add and update images or image url in Volusion using Volusion API -

javascript - jQuery UI Splitter/Resizable for unlimited amount of columns -

javascript - IE9 error '$'is not defined -