使用 GAC 时如何获取用于登录生产的堆栈跟踪信息

发布于 2024-07-15 04:31:11 字数 994 浏览 6 评论 0原文

我想获取堆栈跟踪(文件名和行号)信息,以在生产环境中记录异常等。 DLL 安装在 GAC 中。 有什么办法可以做到这一点吗?

本文介绍了如何将 PDB 文件放入 GAC 中:

您可以轻松发现这些,因为它们会说您需要将调试符号(.pdb 文件)复制到 GAC。 就其本身而言,这是行不通的。

我知道这篇文章涉及使用 VS 进行调试,但我认为它也可能适用于记录堆栈跟踪。

我已按照此问题的说明进行操作,除了取消选中优化代码(他们说这是可选的)。

我将 dll 和 pdb 复制到 GAC 中,但仍然没有获取堆栈跟踪信息。 以下是我在堆栈跟踪的日志文件中得到的内容:

OnAuthenticate at offset 161 in file:line:column <filename unknown>:0:0
ValidateUser at offset 427 in file:line:column <filename unknown>:0:0
LogException at offset 218 in file:line:column <filename unknown>:0:0

我正在使用 NLog。

我的 NLog 布局是:

layout="${date:format=s}|${level}|${callsite}|${identity}|${message}|${stacktrace:format=Raw}"

${stacktrace:format=Raw} 是相关部分。

I would like to get stack trace (file name and line number) information for logging exceptions etc. in a production environment. The DLLs are installed in the GAC. Is there any way to do this?

This article says about putting PDB files in the GAC:

You can spot these easily because they will say you need to copy the debug symbols (.pdb file) to the GAC. In and of itself, that will not work.

I know this article refers to debugging with VS but I thought it might apply to logging the stacktrace also.

I've followed the instructions for the answer to this question except for unchecking Optimize code which they said was optional.

I copied the dlls and pdbs into the GAC but I'm still not getting the stack trace information. Here's what I get in the log file for the stack trace:

OnAuthenticate at offset 161 in file:line:column <filename unknown>:0:0
ValidateUser at offset 427 in file:line:column <filename unknown>:0:0
LogException at offset 218 in file:line:column <filename unknown>:0:0

I'm using NLog.

My NLog layout is:

layout="${date:format=s}|${level}|${callsite}|${identity}|${message}|${stacktrace:format=Raw}"

${stacktrace:format=Raw} being the relevant part.

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

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

发布评论

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

评论(2

烙印 2024-07-22 04:31:11

尝试使用小写的 raw:

   ${stacktrace:format=raw}

如果这不起作用,请尝试:

   ${exception:format=stacktrace}

Try raw in lowercase:

   ${stacktrace:format=raw}

If that doesn't work try:

   ${exception:format=stacktrace}
筱果果 2024-07-22 04:31:11

试试这个:

StringWriter sw = new StringWriter();
new Throwable().printStackTrace(new PrintWriter(sw));
String stackTrace = sw.toString();

字符串 stackTrace 将包含当前线程的 stackstrace

Try this:

StringWriter sw = new StringWriter();
new Throwable().printStackTrace(new PrintWriter(sw));
String stackTrace = sw.toString();

The string stackTrace will have the stackstrace of the current thread

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