Note that there are some explanatory texts on larger screens.

plurals
  1. POTraceSource.TraceEvent() fails logging when Exception message contains non-printable characters
    primarykey
    data
    text
    <p>I have a call to <code>TraceSource.TraceEvent()</code> that is sometimes not writing to the Azure Diagnostics logs.</p> <pre><code>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 } } } </code></pre> <p>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 <code>TraceSource</code> or by <code>DiagnosticMonitor</code>?</p> <p>To further narrow this down, the Exception in question is actually the <code>InnerException</code> of Exception: "There is an error in XML document (72, -499)". The XML that causes the Exception contains invalid character entities, eg <code>&amp;#x11;</code>. Could it be that the Exception message contains some of these character entities and the <code>TraceSource</code> fails to log them?</p> <p><strong>Edit:</strong> I was able to finally repro this in my dev environment and so I was able to examine the Exception in the debugger. The exception that won't log is an <code>XmlException</code>:</p> <blockquote> <p>'', hexadecimal value 0x11, is an invalid character. Line 72, position -499.</p> </blockquote> <p>In between the quotes is the non-printable character - it shows up as a black triangle in the debugger. So, this leads me to believe that my suspicion is correct - Some piece of the logging mechanism doesn't like the non-printable character. So, which piece? Or, more importantly, since it looks like I need to start sanitizing all of my strings when tracing, which characters should I look for to remove?</p> <p>Is there some built in function that will sanitize a string, removing non-printable characters?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload