에 정보를 기록하려면 TraceSource
을 사용하고 있습니다. 내가 로깅하는 메시지는 XML이지만 서비스 추적 뷰어에서 메시지를 볼 때 XML로 표시되지 않고 문자열로 표시됩니다. 이것을 할 수있는 방법이 있습니까? 이 때문에 어쨌든 서비스 추적 뷰어XML로 Service Trace Viewer의 ApplicationData 형식을 지정하십시오.
에 있나요 보여주는 어떻게
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();
}
}
}
그리고 다음과 같습니다 : 가 여기 내의 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>
내 코드입니다 <ApplicationData>
태그 아래에있는 것은 XML로 포맷되어 있습니까?
편집은 내가 svcfile을 열어, 나는 문자열이 제대로 인코딩되지 않은 것을 보았다. 왜 안 그래?
<ApplicationData><log Método="RunSql">drop procedure dbo.spfwug_in_controle_versao</log></ApplicationData>