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 6683987
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:53:11+00:00 2026-05-26T04:53:11+00:00

I’m using TraceSource to log information to a XmlWriterTraceListener . The message I’m logging

  • 0

I’m using TraceSource to log information to a XmlWriterTraceListener. The message I’m logging is a XML, however, when I view the message in Service Trace Viewer, it’s not displayed as a XML, it’s displayed as a string. Is there a way to do this?
Here is my app.config

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.diagnostics>
    <trace autoflush="true" />
    <sources>
      <source name="system.framework.db.utility" switchName="switchInformation">
        <listeners>
          <remove name="Default" />
          <add name="arquivoXml" />
        </listeners>
      </source>
    </sources>
    <switches>
      <add name="switchErro" value="Error"/>
      <add name="switchInformation" value="Information"/>
    </switches>
    <sharedListeners>
      <add name="arquivoXml"
           type="System.Diagnostics.XmlWriterTraceListener"
           initializeData="C:\Temp\trace.svclog">
      </add>
    </sharedListeners>
  </system.diagnostics>
</configuration>

Below is my code:

namespace system.framework.db.utility.sqlserver
{
  internal class SqlDBTransManager : IDBManagerConnection
  {
    private static readonly TraceSource ts = new TraceSource("system.framework.db.utility");

    private void RunSqlInternal(String pSql, DBManagerParams pDBManagerParams, DBManagerConnection pTransac)
    {
      //Lots of code, and below is the log
      StringBuilder sb = new StringBuilder(1000);
      XmlWriterSettings settings = new XmlWriterSettings();
      settings.ConformanceLevel = ConformanceLevel.Document;
      using (XmlWriter xml = XmlWriter.Create(sb, settings))
      {
        xml.WriteStartDocument(true);
        xml.WriteStartElement("log");
        xml.WriteAttributeString("Método", "RunSql");
        xml.WriteString(pSql);
        xml.WriteEndElement();
        xml.WriteEndDocument();
        xml.Flush();
      }
      ts.TraceEvent(TraceEventType.Information, 1, sb.ToString());

      oCommand.ExecuteNonQuery();
    }
  }
}

And below is how it’s showing in Service Trace Viewer

enter image description here

Is there anyway so that what’s under the <ApplicationData> tag is formatted as a XML?

EDIT

I opened the svcfile, and I saw that the string is not encoded properly. Why isn’t it?

<ApplicationData>&lt;log Método=&quot;RunSql&quot;&gt;drop procedure dbo.spfwug_in_controle_versao&lt;/log&gt;</ApplicationData>
  • 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-26T04:53:11+00:00Added an answer on May 26, 2026 at 4:53 am

    I was able to do this dumping the TraceSource, and using the Enterprise Library 5.0. It was a XmlLogEntry that solved my problem. Below is the code:

      internal class SqlDBTransManager : IDBManagerConnection
      {
        private void RunSqlInternal(String pSql, DBManagerParams pDBManagerParams, DBManagerConnection pTransac)
        {
          ////Lots of code, and below is the log
          XmlDocument doc = new XmlDocument();
          XPathNavigator nav = doc.CreateNavigator();
          using (XmlWriter xml = nav.AppendChild())
          {
            xml.WriteStartElement("log");
            xml.WriteAttributeString("Método", "RunSql");
            xml.WriteString(pSql);
            xml.WriteEndElement();
            xml.Flush();
          }
          XmlLogEntry entry = new XmlLogEntry();
          entry.Xml = nav;
          entry.Priority = 1;
          entry.Categories = new String[] { "DB" };
          entry.Severity = TraceEventType.Information;
          Logger.Write(entry);
    
          oCommand.ExecuteNonQuery();
        }
      }
    

    After that, I configure a XML Trace Listener in the web.config:

    <configuration>
      <configSections>
        <section name="loggingConfiguration" type="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.LoggingSettings, Microsoft.Practices.EnterpriseLibrary.Logging, Version=5.0.414.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" requirePermission="true" />
      </configSections>
      <loggingConfiguration name="Logging Application Block" tracingEnabled="true"
        defaultCategory="System.ServiceModel" logWarningsWhenNoCategoriesMatch="true">
        <listeners>
          <add name="XML Trace Listener" type="Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners.XmlTraceListener, Microsoft.Practices.EnterpriseLibrary.Logging"
            listenerDataType="Microsoft.Practices.EnterpriseLibrary.Logging.Configuration.XmlTraceListenerData, Microsoft.Practices.EnterpriseLibrary.Logging"
            fileName="c:\\temp\\trace_framework.svclog" traceOutputOptions="DateTime, Timestamp, ProcessId, ThreadId" />
        </listeners>
        <categorySources>
          <add switchValue="All" name="System.ServiceModel">
            <listeners>
              <add name="XML Trace Listener" />
            </listeners>
          </add>
        </categorySources>
        <specialSources>
          <allEvents switchValue="All" name="All Events">
            <listeners>
              <add name="XML Trace Listener" />
            </listeners>
          </allEvents>
          <notProcessed switchValue="All" name="Unprocessed Category">
            <listeners>
              <add name="XML Trace Listener" />
            </listeners>
          </notProcessed>
          <errors switchValue="All" name="Logging Errors &amp; Warnings">
            <listeners>
              <add name="XML Trace Listener" />
            </listeners>
          </errors>
        </specialSources>
      </loggingConfiguration>
    

    After this, the XML that I send is correctly formatted as a XML in the svclog format.

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

Sidebar

Related Questions

We are using XSLT to translate a RIXML file to XML. Our RIXML contains
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
That's pretty much it. I'm using Nokogiri to scrape a web page what has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I'm using v2.0 of ClassTextile.php, with the following call: $testimonial_text = $textile->TextileRestricted($_POST['testimonial']); ... and
We're building an app, our first using Rails 3, and we're having to build
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;
I need a function that will clean a strings' special characters. I do NOT
I have thousands of HTML files to process using Groovy/Java and I need 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.