System.Diagnostics.StackTrace是错误的受害者 [英] System.Diagnostics.StackTrace is wrong sometims

查看:398
本文介绍了System.Diagnostics.StackTrace是错误的受害者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用System.Diagnostics.StackTrace获取

当前函数的堆栈跟踪,将函数的名称打印到日志中,并且

有时候它会显示一个甚至不写入日志的函数

就是写入日志的内容。这不可能,所以

System.Diagnostics.StackTrace必须返回错误的信息

(从另一个线程,我猜)。


这是正常的还是预期的?它可靠吗?


Zytan

I use System.Diagnostics.StackTrace to get the stack trace of the
current function, to print out the function''s name to the log, and
sometimes it shows that a function that doesn''t even write to the log
is what is writing to the log. This just can''t be, so
System.Diagnostics.StackTrace must be returning the wrong information
(from another thread, i suppose).

Is this normal, or expected? Can it be reliable?

Zytan

推荐答案

我对此表示怀疑。更有可能的是你没有将访问权限同步到日志,所以你正在编写与每个

其他混合的堆栈跟踪。


您需要做的是同步对日志文件的访问,写出堆栈跟踪的
,或者,与每个文件相关联的某种关联ID
您写的
堆栈跟踪,这将允许您稍后将所有

信息分组。

-

- Nicholas Paldino [.NET / C#MVP]

- mv*@spam.guard.caspershouse.com


" Zytan" < zy ********** @ gmail.comwrote in message

news:11 ******************** **@b40g2000prd.googlegr oups.com ...
I doubt it. What''s more than likely is you are not synchronizing access
to the log, so you are writing stack traces that are intermingled with each
other.

What you need to do is synchronize access to the log file, writing out
the stack traces, or, have some sort of correlation id associated with each
stack trace that you write, which will allow you to group all the
information later.
--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Zytan" <zy**********@gmail.comwrote in message
news:11**********************@b40g2000prd.googlegr oups.com...

>我使用System.Diagnostics.StackTrace来获取
$ b的堆栈跟踪$ b当前函数,将函数的名称打印到日志中,

有时它会显示一个甚至不写入日志的函数

是写入日志的内容。这不可能,所以

System.Diagnostics.StackTrace必须返回错误的信息

(从另一个线程,我猜)。


这是正常的还是预期的?它可靠吗?


Zytan
>I use System.Diagnostics.StackTrace to get the stack trace of the
current function, to print out the function''s name to the log, and
sometimes it shows that a function that doesn''t even write to the log
is what is writing to the log. This just can''t be, so
System.Diagnostics.StackTrace must be returning the wrong information
(from another thread, i suppose).

Is this normal, or expected? Can it be reliable?

Zytan



" Nicholas Paldino [.NET / C# MVP] QUOT; < mv*@spam.guard.caspershouse.com写在

消息新闻:%2 **************** @ TK2MSFTNGP04.phx.gbl .. 。
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.comwrote in
message news:%2****************@TK2MSFTNGP04.phx.gbl...

我对此表示怀疑。更有可能的是你没有同步

访问日志,所以你正在编写彼此混合的堆栈跟踪


I doubt it. What''s more than likely is you are not synchronizing
access to the log, so you are writing stack traces that are intermingled
with each other.



我怀疑StackTrace也是错误的。然而,Zytan的观点是

函数名称会在日志中结束,而这些日志应该*永远不会出现在日志中。它不是因为他们的顺序错误而是
。这就是他们应该永远不会出现



为此,我没有解释。


Zytan,如果你能提供一个简洁的代码示例,可以有效地再现问题,那将会有所帮助。


Pete

I doubt that the StackTrace is wrong too. However, Zytan''s point is that
function names wind up in the log that should *never* be in the log. It''s
not that they''re in the wrong order. It''s that they should just never
appear at all.

For that, I have no explanation.

Zytan, if you can provide a concise example of code that reliably reproduces
the problem, that would be helpful.

Pete


我对此表示怀疑。更有可能的是你没有将访问
I doubt it. What''s more than likely is you are not synchronizing access

同步到日志中,所以你正在编写与每个混合访问的堆栈跟踪

其他。
to the log, so you are writing stack traces that are intermingled with each
other.



很可能。我正在使用TextWriter,它是同步的,但是如果

我对我的LogWrite函数进行了两次调用,那么它们可以混合起来

up。问题是我可以看到这样的事情何时发生,而且我的问题经常发生,它必须是别的东西。虽然,你的

点已经被拿走了,但是我会解决这个问题,即使它很难发生,也可以将它作为一种可能性删除。


我会回复Peter的帖子,我认为这是真正的问题...


谢谢,

Zytan

That is likely. I am using TextWriter, which is synchronized, but if
I make two calls to my LogWrite function, then they could get mixed
up. The problem is that I can see when such a thing happens, and my
issues occur so often, it must be something else. Although, your
point is taken, and I''ll solve this issue ANYWAY, even though it
hardly happens, to remove that as a possibility.

I''ll reply to Peter''s post with what I think is the real issue...

thanks,
Zytan


这篇关于System.Diagnostics.StackTrace是错误的受害者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆