c# - 如何在 azure 函数的堆栈跟踪中显示文件名和行号
问题描述
注意:如果有人对如何做到这一点有丝毫的想法,请写下答案:)
如何启用一个功能,以便在调试时在 azure 函数控制台窗口中显示的堆栈跟踪中捕获每个异常的文件名和行号。甚至更好的是,在调试 azure 函数时,如何在 Visual Studio 中触发调试断点?
我试过启用调试信息=完整,在项目设置->构建->高级->调试信息=完整,但这没有任何效果。
下面是一些代码,它们会生成一个索引越界异常来说明问题:
List<string> test = new List<string>();
Console.WriteLine(test[0]);
当我在调试模式下运行 azure 函数并遇到异常时,这是控制台窗口生成的输出:
[2020-10-02T13:01:38.289] Executed 'Function1' (Failed, Id=180bf39f-1b60-401e-80a4-2073de926e9e, Duration=340ms)
[2020-10-02T13:01:38.290] System.Private.CoreLib: Exception while executing function: Function1. System.Private.CoreLib: One or more errors occurred. (Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index')). System.Private.CoreLib: Index was out of range. Must be non-negative and less than the size of the collection. (Parameter 'index').
这是项目中的 Host.json 文件:
解决方案
您只启用了 ApplicationInsight 日志。
将以下行添加到您的配置中
{
"Logging": {
"LogLevel": {
"Default": "Debug",
"System": "Information",
"Microsoft": "Information"
}
}
}
然后像下面这样修改日志记录配置
services.AddLogging(config =>
{
// clear out default configuration ==> if necessary
config.ClearProviders();
config.AddConfiguration(Configuration.GetSection("Logging"));
config.AddDebug();
if(Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT") == EnvironmentName.Development)
{
config.AddConsole();
}
});
推荐阅读
- django - Django 复杂模型和嵌套查询
- javascript - 车把多选助手
- python - 将 MongoAlchemy 模型转换为 PyMongo
- spring-boot - H2 不使用 Spring Boot 将我的 jsp Web 表单更新到我的简单数据库
- swift - 视图第二次没有出现 [Swift]
- sql-server - 如何在 SQL Server 中禁用多线程?
- ruby-on-rails - Why is Ruby not updating after updating with Ruby Installer?
- python-3.x - 按列连接两个数据框
- excel - Excel:通过从另一个选项卡中引入相应的单元格来填充新列
- algorithm - 为 sha256 创建 2 路地图。