不要在堆栈跟踪中显示构建机器的文件路径

发布于 2024-08-19 13:19:07 字数 381 浏览 8 评论 0原文

我目前正在开发一个 C# 应用程序,它有自己的日志记录。当抛出异常时,异常被保存到一个列表中,用户可以通过列表视图查看该列表。 当用户单击列表视图中的异常时,该异常的堆栈跟踪将显示在文本框中。但即使当我在远程计算机上执行程序时,堆栈跟踪也会显示从编译应用程序的计算机到原始源文件的文件路径。

例如:

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

只显示没有文件夹的源文件就好了...

我怎样才能改变这种行为?

有没有原生解决方案?或者我必须简单地进行一些字符串操作?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

海拔太高太耀眼 2024-08-26 13:19:07

您可能拥有已安装应用程序的 .pdb 文件。如果没有 .pdb 文件,它不应显示文件位置。

查看 获取异常堆栈跟踪中的行号在Windows服务中

在堆栈跟踪中包含行号,而不pdb?

您无法使用 line 获取堆栈跟踪
直接来自您的申请的号码
除非你捆绑 PDB。

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.

诗化ㄋ丶相逢 2024-08-26 13:19:07

文件路径包含在“程序数据库”文件 (.pdb) 中。此类文件是在编译期间创建的,这些文件中的路径与编译机器上的路径相同。

您可以从安装中删除 .pdb 文件,但这样您的堆栈跟踪将只有现在的一半,因为它不会告诉您发生错误的行。通常,您不会在附加 Pdb 文件的生产环境中运行代码。

如果您想保留“有趣的堆栈跟踪”,可以考虑在调用 exceptionObject.toString() 后对文件夹名称进行字符串替换。

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().

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文