Do not show file paths of build machine in stack trace [duplicate]
Asked Answered
L

2

28

I am currently developing a C# application which has got it's own logging. When exceptions are thrown, the exception is saved into a list which can be viewed by the user via a list view. When the user clicks on a exception in the list view, the stack trace of the exception is shown in a text box. But even when I am executing the program on a remote machine, the stack trace shows the file paths to the original source files from the machine where the application was compiled.

e.g.:

at C:\Folder1\Folder2\Class1.cs:81
at C:\Folder1\Folder2\Class2.cs:65
at C:\Folder1\Folder1\Class3.cs:21

Only displaying the source files without folders would be nice...

How can I change this behaviour?

Is there any native solution? Or do I have to simply do some string manipulation?

Lifeanddeath answered 26/1, 2010 at 12:16 Comment(3)
What does your logging code look like?Rouge
Simply filter the path with a Regex expression. Or Path.GetFileName().Caparison
This question is not duplicate, it asks how to NOT display build path and other one is asking WHY there is a build path in exceptions.Asyndeton
P
25

You probably have the .pdb files with the installed app. Without the .pdb files, it should not show the file locations.

Have a look at Getting line numbers in exception stack trace in a Windows Service

and include line numbers in stack trace without pdb?

You can't get a stack trace with line numbers directly from your application unless you bundle the PDB.

Pforzheim answered 26/1, 2010 at 12:19 Comment(1)
Why this is accepted answer? It answers very little to question.Asyndeton
C
10

The file paths are included in "program database" files (.pdb). Such files are created during compilation and paths in these files are as on the compilation machine.

You can remove the .pdb files from your installation, but this way your stack trace will be just half as interesting as it is now, since it will not tell you the line on which the error happened. Normally, you don't run code in production environment with Pdb files attached.

If you want to keep the "interesting stack trace", you can consider doing a string replacement of folder names, after you have called exceptionObject.toString().

Chiekochien answered 26/1, 2010 at 12:23 Comment(1)
Why don't you ... run code in production environment with Pdb files attached?Circosta

© 2022 - 2024 — McMap. All rights reserved.