问题
I followed the steps mentioned in this article http://dotnetslackers.com/articles/aspnet/Getting-ELMAH-to-work-with-WCF-services.aspx to configure WCF service to setup error logging by ELMAH. it works with wsHttpBinding with Visual studio webserver, but when I host it in IIS (5/6) and change the binding to basicHttpBinding, it is not logging the errors. I tried to change the error signalling code to "Elmah.ErrorLog.GetDefault(null).Log(new Error(ex));
" as mentioned at this link ELMAH - Exception Logging without having HttpContext, but that didn't help either. not sure what else I need to do. Please help. here is the config for the WCF service (I tried commenting and uncommenting the aspnetcompatibility as well, but didn't work). if there is a working sample with basicHttpBinding, that would be very helpful. thanks in advance.
<system.serviceModel>
<!--<serviceHostingEnvironment aspNetCompatibilityEnabled="true" />-->
<bindings>
<basicHttpBinding>
<binding name="BasicHttpEndpointBinding">
<security mode="TransportCredentialOnly">
<transport clientCredentialType="Windows" />
</security>
</binding>
</basicHttpBinding>
</bindings>
<services>
<service behaviorConfiguration="ElmahWCF.Service1Behavior" name="ElmahWCF.Service1">
<endpoint address="" binding="basicHttpBinding"
bindingConfiguration="BasicHttpEndpointBinding"
name="BasicHttpEndpoint" contract="ElmahWCF.IService1">
</endpoint>
</service>
</services>
<behaviors>
<serviceBehaviors>
<behavior name="ElmahWCF.Service1Behavior">
<!--To avoid disclosing metadata information, set the value below to false and remove the metadata endpoint above before deployment-->
<serviceMetadata httpGetEnabled="true"/>
<!--To receive exception details in faults for debugging purposes, set the value below to true. Set to false before deployment to avoid disclosing exception information-->
<serviceDebug includeExceptionDetailInFaults="false"/>
</behavior>
</serviceBehaviors>
</behaviors>
</system.serviceModel>
回答1:
I figured out that it is sending mails, but not logging errors to database. it could be permissions issue with database (even though I have full access to the database for my windows login Id and it logs fine when hosted in visual studio webserver and wsHttpBinding is used). I deployed it to the server and configured with a different account in an application pool and after that it is logging errors successfully to the database without having to make any changes to the code from the article. I am still not sure why it doesn't log the errors to database from local IIS (I even tried setting impersonation to true in web.config so that it uses my id when logging), but that's not a big issue for me, since it works fine after deployment. thanks.
来源:https://stackoverflow.com/questions/4470362/error-logging-by-elmah-not-working-in-wcf-service-hosted-in-iis-with-basichttpbi