如何登录陷入WCF服务异常部署到Azure上异常、WCF、Azure

2023-09-03 12:48:27 作者:45角度的天空有流星划过

什么是登录托管在云夹在WCF服务异常的最好方法是什么?

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

推荐答案

您可以System.Diagnostics程序的优势,并与 Trace.traceError记录你的异常()。然后,您可以安排这些跟踪语句定期上传到表存储(也许每分钟一次),在这里你就可以检索和分析的跟踪语句要么在辅助角色的导通premise应用程序或一个运行。

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.

例如:在你的Worker角色的的OnStart(),自定义诊断管理您的跟踪数据上传到表存储。在这个例子中,它的上传每一分钟,在DiagnosticsConnectionString规定(这是在默认情况下,设置为指向dev的存储)存储账户:

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);

然后,当你遇到你的WCF服务异常,记录它:

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

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

最后,无论是写一些code查询诊断数据,或者使用类似的新的内置Visual Studio中的存储资源管理器查看和行为上的错误。

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.