问题描述
我要打电话 TraceSource.TraceEvent()
是有时不写入Azure诊断日志。
I have a call to TraceSource.TraceEvent()
that is sometimes not writing to the Azure Diagnostics logs.
public class WorkerRole : RoleEntryPoint
{
private TraceSource trace = new TraceSource(
"ImportService", SourceLevels.Information);
public override void Run()
{
...
try
{
...
}
catch (Exception ex)
{
bool hasMsg = !string.IsNullOrEmpty(ex.Message);
trace.TraceEvent(TraceEventType.Error, 0,
"ex has message: " + hasMsg.ToString()); // this gets logged
trace.TraceEvent(TraceEventType.Error, 0,
"Inner exception message: " + ex.Message); // this does not
}
}
}
在某些情况下,因为我无法读取异常消息我不能告诉,第二个电话不会在WADLogsTable找到。是否有某些字符不允许的,无论是由 TraceSource
或 DiagnosticMonitor
?
In certain cases, and I can't tell which since I can't read the Exception message, the second call is not found in the WADLogsTable. Are there certain characters that are not allowed, either by TraceSource
or by DiagnosticMonitor
?
要进一步缩小下来,有问题的异常实际上是的InnerException
的异常:有XML文档(72,-499)在一个错误。导致异常的XML包含无效字符实体,例如&放大器;#X11;
。会不会是例外消息包含一些字符实体和 TraceSource
的登录失败呢?
To further narrow this down, the Exception in question is actually the InnerException
of Exception: "There is an error in XML document (72, -499)". The XML that causes the Exception contains invalid character entities, eg 
. Could it be that the Exception message contains some of these character entities and the TraceSource
fails to log them?
Losing line breaks was a side effect of RemoveControlChars()
. I didn't realize that \r
and \n
are included as "control characters". I've updated my regular expression to not replace \r
and \n
characters.
我不喜欢接受我自己的答案,所以如果你有一个替代的解决方案或改进矿山,请发表它,如果它的更好,我会接受它。
I don't like accepting my own answer, so if you have an alternate solution or an improvement to mine, please post it and if it's better, I'll accept it.
这篇关于TraceSource.TraceEvent()失败时,异常信息中包含非打印字符记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!