Luk*_*kas 8 c# asp.net-mvc build pdb-files asp.net-core
当我发布 ASP.NET MVC Core 3.1 应用程序时,异常日志包含开发人员计算机的路径。
日志示例:
2021-04-27 16:36:47.1954 | |18f76390-4123opr9fjnfe832. | ERROR | Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware | An unhandled exception has occurred while executing the request. | System.Exception: TEST
at ClassLibrary.Repositories.HomeRepo.GetSummary() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......:line 68
at ClassLibrary.Services.HomeService.GetStatuses() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......:line 38
at Project.Controllers.HomeController.GetSummary() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......\HomeController.cs:line 39
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
......
......
Run Code Online (Sandbox Code Playgroud)
行号和文件位置对于识别错误原因很有用,但路径包含开发人员的名称FLASTNAME
,如果不存在的话我更希望如此。
我的研究最接近的是 .pdb 文件(1 , 2),一些建议更改构建设置中的调试信息:
但是,我尝试了每个选项,但它仍然显示完整路径。我无法选择在另一台机器上构建项目,那么在这种情况下我该怎么办?
我知道我可能在这里误解了一些东西,但即使在Release
配置中构建项目也不能解决我的问题。
编辑:
<PathMap>
这是@Kirk Larkin 建议添加代码的结果
<PropertyGroup>
<PathMap>$(MSBuildProjectDirectory)=ANOTHERPATH</PathMap>
</PropertyGroup>
Run Code Online (Sandbox Code Playgroud)
到项目的 csproj 文件:
2021-04-27 16:36:47.1954 | |18f76390-4123opr9fjnfe832. | ERROR | Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware | An unhandled exception has occurred while executing the request. | System.Exception: TEST
at ClassLibrary.Repositories.HomeRepo.GetSummary() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......:line 68
at ClassLibrary.Services.HomeService.GetStatuses() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......:line 38
at Project.Controllers.HomeController.GetSummary() in ANOTHERPATH\Controllers\HomeController.cs:line 39
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
......
......
Run Code Online (Sandbox Code Playgroud)
HomeController
所以它只影响跟踪中部分的路径。这与我在高级构建设置中将调试信息设置为时发生的情况类似:None
2021-04-27 16:36:47.1954 | |18f76390-4123opr9fjnfe832. | ERROR | Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware | An unhandled exception has occurred while executing the request. | System.Exception: TEST
at ClassLibrary.Repositories.HomeRepo.GetSummary() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......:line 68
at ClassLibrary.Services.HomeService.GetStatuses() in C:\Users\FLASTNAME\TFS\dotnet\APPNAME\.......:line 38
at Project.Controllers.HomeController.GetSummary()
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
......
......
Run Code Online (Sandbox Code Playgroud)
除了这里我没有得到该HomeController
部分的任何路径或行号。
Luk*_*kas 13
感谢@KirkLarkin,我们能够解决我的问题。
对我来说最好的选择是在解决方案下创建一个Directory.Build.props文件(解决方案项目文件夹是自动生成的):
我的 Directory.Build.props 文件具有以下代码:
<Project>
<PropertyGroup>
<PathMap>$(MSBuildProjectDirectory)=$(MSBuildProjectName)</PathMap>
</PropertyGroup>
</Project>
Run Code Online (Sandbox Code Playgroud)
这会将每个项目的构建目录映射为项目的名称,从而产生所需的缩短路径:
2021-04-27 16:36:47.1954 | |18f76390-4123opr9fjnfe832. | ERROR | Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware | An unhandled exception has occurred while executing the request. | System.Exception: TEST
at ClassLibrary.Repositories.HomeRepo.GetSummary() in ClassLibrary\.......:line 68
at ClassLibrary.Services.HomeService.GetStatuses() in ClassLibrary\.......:line 38
at Project.Controllers.HomeController.GetSummary() in Project\.......\HomeController.cs:line 39
at lambda_method(Closure , Object )
at Microsoft.Extensions.Internal.ObjectMethodExecutorAwaitable.Awaiter.GetResult()
......
......
Run Code Online (Sandbox Code Playgroud)
如果您只需要对一个项目执行此操作,则可以编辑该项目的 .csproj 文件以包含<PathMap>
嵌套在<PropertyGroup>
标记内的代码。
归档时间: |
|
查看次数: |
1139 次 |
最近记录: |