gpt4 book ai didi

asp.net-mvc - 如何将异常记录到 Azure 应用程序日志

转载 作者:行者123 更新时间:2023-12-03 00:47:08 25 4
gpt4 key购买 nike

我有一个托管在 Azure Web 服务中的 ASP.Net MVC Web 应用程序。我需要将异常记录到应用程序日志中。

稍后我想检查和回顾发生了什么样的异常。

我该怎么做?

最佳答案

如果你所说的异常是指那些在 try-catch 中捕获的异常,那么你可以这样做;

  1. 按照此处提到的步骤操作,您需要在 Azure Web 应用程序上切换此设置;

    Your App > App Service Logs > Turn On Application Logging (FileSystem)

  2. 然后使用下面的代码; Trace.Information()、Trace.Warning()、Trace.Error()

using System.Diagnostics;

public ActionResult sample(){
try{
Trace.Information("Hello World!");
}catch(exception e){
Trace.Error(e.Message);
}
}

关于asp.net-mvc - 如何将异常记录到 Azure 应用程序日志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61100131/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com