How to Log exceptions caught in WCF service deployed on Azure

最后都变了- 提交于 2019-12-04 19:52:33

问题


What is the best way to log the exceptions caught in WCF service hosted on cloud?


回答1:


You can take advantage of System.Diagnostics and logging your exceptions with Trace.traceError(). You can then schedule these trace statements to be periodically uploaded to table storage (maybe once a minute?), where you can then retrieve and analyze the trace statements either with an on-premise app or one running in a worker role.

For example: in your worker role's OnStart(), customize the Diagnostic Manager to upload your trace data to table storage. In this example, it's uploading every minute, to the storage account specified in DiagnosticsConnectionString (this is, by default, set up to point to dev storage):

var diag = DiagnosticMonitor.GetDefaultInitialConfiguration();
diag.Logs.ScheduledTransferLogLevelFilter = LogLevel.Information;
diag.Logs.ScheduledTransferPeriod = TimeSpan.FromMinutes(1.0);
DiagnosticMonitor.Start("DiagnosticsConnectionString", diag);

Then, whenever you encounter an exception in your WCF Service, log it:

System.Diagnostics.Trace.TraceError("WCF Error caught: ...");

Finally, either write some code to query the diagnostic data, or use something like the new built-in Visual Studio storage explorer to view and act on the errors.



来源:https://stackoverflow.com/questions/3083577/how-to-log-exceptions-caught-in-wcf-service-deployed-on-azure

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