ELMAH-Logowanie WYJĄTKÓW bez posiadania HttpContext

Próbowałem tego rozwiązania z Elmah.XmlFileErrorLog ale dostaję następujący wyjątek

System.ArgumentNullException was unhandled by user code
  Message="Value cannot be null.\r\nParameter name: context"
  Source="Elmah"
  ParamName="context"
  StackTrace:
       at Elmah.ErrorSignal.FromContext(HttpContext context) in c:\builds\ELMAH\src\Elmah\ErrorSignal.cs:line 67
       at Elmah.ErrorSignal.FromCurrentContext() in c:\builds\ELMAH\src\Elmah\ErrorSignal.cs:line 61
       at ElmahHttpErrorHandler.ProvideFault(Exception error, MessageVersion version, Message& fault) in c:\Myapplication\App_Code\Util\ElmahHttpErrorHandler.cs:line 19
       at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideFault(Exception e, FaultConverter faultConverter, ErrorHandlerFaultInfo& faultInfo)
       at System.ServiceModel.Dispatcher.ErrorBehavior.ProvideMessageFaultCore(MessageRpc& rpc)
       at System.ServiceModel.Dispatcher.ImmutableDispatchRuntime.ProcessMessageCleanup(MessageRpc& rpc)
  InnerException: 

Www.Plik konfiguracyjny

<configSections>
    <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <section name="exceptionHandling" type="Microsoft.Practices.EnterpriseLibrary.ExceptionHandling.Configuration.ExceptionHandlingSettings, Microsoft.Practices.EnterpriseLibrary.ExceptionHandling, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <section name="dataConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Data.Configuration.DatabaseSettings, Microsoft.Practices.EnterpriseLibrary.Data, Version=4.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
    <sectionGroup name="system.web.extensions" type="System.Web.Configuration.SystemWebExtensionsSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
        <sectionGroup name="scripting" type="System.Web.Configuration.ScriptingSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
            <section name="scriptResourceHandler" type="System.Web.Configuration.ScriptingScriptResourceHandlerSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
            <sectionGroup name="webServices" type="System.Web.Configuration.ScriptingWebServicesSectionGroup, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
                <section name="jsonSerialization" type="System.Web.Configuration.ScriptingJsonSerializationSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="Everywhere"/>
                <section name="profileService" type="System.Web.Configuration.ScriptingProfileServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                <section name="authenticationService" type="System.Web.Configuration.ScriptingAuthenticationServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
                <section name="roleService" type="System.Web.Configuration.ScriptingRoleServiceSection, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" requirePermission="false" allowDefinition="MachineToApplication"/>
            </sectionGroup>
        </sectionGroup>
    </sectionGroup>
  <sectionGroup name="elmah">
    <section name="security" requirePermission="false" type="Elmah.SecuritySectionHandler, Elmah" />
    <section name="errorLog" requirePermission="false" type="Elmah.ErrorLogSectionHandler, Elmah" />
    <section name="errorMail" requirePermission="false" type="Elmah.ErrorMailSectionHandler, Elmah" />
    <section name="errorFilter" requirePermission="false" type="Elmah.ErrorFilterSectionHandler, Elmah" />
  </sectionGroup>
</configSections>
<httpHandlers>
  <add verb="POST,GET,HEAD" path="elmah.axd" type="Elmah.ErrorLogPageFactory, Elmah" />
  <remove verb="*" path="*.asmx"/>
    <add verb="*" path="*.asmx" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="*" path="*_AppService.axd" validate="false" type="System.Web.Script.Services.ScriptHandlerFactory, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
    <add verb="GET,HEAD" path="ScriptResource.axd" type="System.Web.Handlers.ScriptResourceHandler, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35" validate="false"/>
</httpHandlers>
<httpModules>
    <add name="ScriptModule" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=3.5.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
  <add name="ErrorLog" type="Elmah.ErrorLogModule, Elmah" />
</httpModules>
...

<elmah>
  <errorLog type="Elmah.XmlFileErrorLog, Elmah" logPath="~/App_Data" />
  <security allowRemoteAccess="1" />
</elmah>

Używam windows 7. czy może być z tym jakiś problem?

UPDATE Uwaga: prowadzę serwis WCF ASP.NET. czyli dodałem projekt usługi WCF do rozwiązania poprzez dodanie nowej strony internetowej, a następnie wybranie szablonu usługi WCF. Obecnie uruchamiam go z poziomu IDE. Hosting go na IIS również nie pomógł.

Author: Community, 2010-06-08

4 answers

Odpowiadam na własne pytanie.

Próbowałem dodać following w mojej sieci.config

<system.serviceModel>
  <serviceHostingEnvironment aspNetCompatibilityEnabled="true" />
</system.serviceModel>

Również udekorował moją służbę następującym atrybutem

[AspNetCompatibilityRequirements(RequirementsMode = AspNetCompatibilityRequirementsMode.Required)]    
public class CalculatorService : ICalculatorSession    
{
    // Implement calculator service methods
 }
Nadal nie ma sensu. Następnie mam rozwiązanie tutaj , dzięki któremu można użyć Elmah bez HTTPContext. np. błędy logowania przez zapis
Elmah.ErrorLog.GetDefault(null).Log(new Error(ex));

Zamiast

Elmah.ErrorSignal.FromCurrentContext().Raise(error);
 83
Author: IsmailS,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2015-08-18 05:36:12

Dzięki wszystkim, oto moja klasa ErrorHelper, którą wymyśliłem, aby ręcznie logować błędy na stronach internetowych i w usługach WCF, usługach windows itp:

    public static class ErrorHelper
{
    /// <summary>
    /// Manually log an exception to Elmah.  This is very useful for the agents that try/catch all the errors.
    /// 
    /// In order for this to work elmah must be setup in the web.config/app.config file
    /// </summary>
    /// <param name="ex"></param>
    public static void LogErrorManually(Exception ex)
    {
        if (HttpContext.Current != null)//website is logging the error
        {                
            var elmahCon = Elmah.ErrorSignal.FromCurrentContext();
            elmahCon.Raise(ex);
        }
        else//non website, probably an agent
        {                
            var elmahCon = Elmah.ErrorLog.GetDefault(null);
            elmahCon.Log(new Elmah.Error(ex));
        }
    }
}
 33
Author: jhilden,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2012-06-06 19:19:09

Jedynym stabilnym rozwiązaniem, jakie znalazłem, jest usunięcie sieci.atrybut config i użyj atrybutu service behavior, którego używają w logowaniu WYJĄTKÓW dla usług WCF za pomocą ELMAH

 1
Author: Community,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2017-05-23 12:32:24

Czy uruchamiasz ten kod w ASP.NET? Wygląda na to, że HttpContext ma wartość null i powoduje to, że kod ELmah wyrzuca wyjątek-metodę Elmah.ErrorSignal.FromCurrentContext () przejdzie przez HttpContext.Prąd z tego co pamiętam (minęło trochę czasu od przyjrzenia się temu) do Elmah.ErrorSignal.Metoda FromContext (HttpContext context) i wydaje się, że jest to null, co normalnie nie miałoby miejsca w Asp.Net hosting rzeczy.

Inną możliwością jest to, że dzieje się to na zewnątrz żądanie do serwera, więc HttpContext może być null

 0
Author: saret,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/doraprojects.net/template/agent.layouts/content.php on line 54
2010-06-08 13:42:25