Skip to content

Instantly share code, notes, and snippets.

@mgonzales3
Created March 13, 2015 14:50
Show Gist options
  • Save mgonzales3/a8813345cb557aea1885 to your computer and use it in GitHub Desktop.
Save mgonzales3/a8813345cb557aea1885 to your computer and use it in GitHub Desktop.
Trace EWS
/*
Currently EWS returns strings with the declaration in the wrong place. This file fixes that.
*/
public class TraceListener : ITraceListener
{
public void Trace(string traceType, string traceMessage)
{
CreateXMLTextFile(traceType, traceMessage.ToString());
}
private void CreateXMLTextFile(string fileName, string traceContent)
{
string updatedContent = "";
try
{
updatedContent = traceContent;
if (traceContent.IndexOf("?xml") > -1)
updatedContent = traceContent.Remove(traceContent.IndexOf("?xml"), 42);
XDocument xd = XDocument.Parse(updatedContent);
xd.Save(AppDomain.CurrentDomain.BaseDirectory + @"Trace\Exchange\" + fileName + ".xml", SaveOptions.None);
}
catch
{
// If the trace data is not valid XML, save it as a text document.
System.IO.File.WriteAllText(AppDomain.CurrentDomain.BaseDirectory + @"Trace\Exchange\" + fileName + ".txt", traceContent);
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment