Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6650563
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T00:54:25+00:00 2026-05-26T00:54:25+00:00

I have a call to TraceSource.TraceEvent() that is sometimes not writing to the Azure

  • 0

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
        }
    }
}

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?

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?

Edit: 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 XmlException:

”, hexadecimal value 0x11, is an invalid character. Line 72, position -499.

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?

Is there some built in function that will sanitize a string, removing non-printable characters?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T00:54:26+00:00Added an answer on May 26, 2026 at 12:54 am

    The answer to another question helped me to figure out a solution. I added a couple of extension methods for convenience:

    public static string RemoveControlChars(this string s)
    {
        return Regex.Replace(s, @"(?![\r\n])\p{Cc}", "");
    }
    public static void TraceEvent(this TraceSource trace, 
        TraceEventType eventType, MyEvtEnum eventId, string message)
    {
        trace.TraceEvent(eventType, (int)eventId, message.RemoveControlChars());
    }
    

    I like the added benefit of not having to cast MyEvtEnum to int every time I call TraceEvent and it adds a natural overload, so this feels like a double win.

    It bothers me that I have to do this at all. One of the primary uses of a diagnostics system is to log Exceptions. Such a diagnostics system should be able to handle any string that an Exception message might contain. I also lose line breaks, which is frustrating. Edit: 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.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a call to a model which is just a standard class (not
I have a call to powershell.exe that looks like this, and which works from
I have to call stored procs in C# (.Net 2.0) sometimes using an ODBC
I have a call back url, that i'm am pulling out the Lat and
I often have call hierarchies in that all methods need the same parameters. If
I have a call logging database that I would like to pull team information
I have to call a Web service that is extremely demanding (unstandard) regarding the
I have a call to a method that returns a UIElement that I call
I have to call some badly written 3rd party COM components that have memory
i have class call example1 this class defines a background, and i want to

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.