Catching all unhandled exceptions in WCF web service in c#

我只是一个虾纸丫 提交于 2019-12-12 03:25:53

问题


I need to catch all unhandled exceptions in my web service.

My service is created with Visual Studio Express 2013 for Web and it is a WCF service style using c#.

I already do that in Android but I have no idea how to do it with the WCF service. Any ideas?


回答1:


As far as I know it is not possible to do that in code as you can do in Android but you can enable tracing in the Web.config file this way:

<?xml version="1.0" encoding="utf-8"?>
<configuration>

       ...your other settings...

       <!-- Trace: -->
       <system.diagnostics>
          <sources>
                <source name="System.ServiceModel" 
                        switchValue="Error"
                        propagateActivity="true">
                <listeners>
                   <add name="traceListener" 
                       type="System.Diagnostics.XmlWriterTraceListener" 
                       initializeData= "C:\Logs\MyTraces.svclog" />
                </listeners>
             </source>
          </sources>
       </system.diagnostics>       

</configuration>

The switchValue="Error" can be changed depending on the level you want. More info: http://www.topwcftutorials.net/2012/06/4-simple-steps-to-enable-tracing-in-wcf.html https://msdn.microsoft.com/en-us/library/ms733025(v=vs.110).aspx



来源:https://stackoverflow.com/questions/34989967/catching-all-unhandled-exceptions-in-wcf-web-service-in-c-sharp

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!