When I publish a ASP.NET MVC Core 3.1 application, the logs of exceptions contain the path of the developers machine.
Example of a log:
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()
......
......
The line number and file location is useful to identify causes of bugs, but the path includes the developer's name FLASTNAME
and I'd prefer if that wasn't there.
The closest thing my research lead me to is .pdb files (1, 2), some suggesting to change the debugging information in build settings:
However, I tried every option but it still shows the full paths. I don't have the option to build the project on another machine, so what could I do in this case?
I know I'm probably misunderstanding something here, but even building project in Release
configuration doesn't solve my problem.
EDIT:
Here is the result of @Kirk Larkin's suggestion to add <PathMap>
code
<PropertyGroup>
<PathMap>$(MSBuildProjectDirectory)=ANOTHERPATH</PathMap>
</PropertyGroup>
to project's csproj file:
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()
......
......
So it only affected the path for the HomeController
part in the trace. This is similar to what happens if I set Debugging information to None
in Advanced Build Settings:
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()
......
......
except here I don't get any path or the line number for the HomeController
part.
Thanks to @KirkLarkin, we were able to solve my issue.
The best option for me was to create a single Directory.Build.props file under the solution (the Solution Items folder was generated automatically):
My Directory.Build.props file has the following code:
<Project>
<PropertyGroup>
<PathMap>$(MSBuildProjectDirectory)=$(MSBuildProjectName)</PathMap>
</PropertyGroup>
</Project>
which will map each project's build directory to be just the project's name, resulting in the desired shortened paths:
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()
......
......
If you need to do this for only one project, you can instead edit the project's .csproj file to contain the <PathMap>
code nested inside a <PropertyGroup>
tag.