**** Merged from MCS ****
[mono-project.git] / mcs / class / Microsoft.Web.Services / Microsoft.Web.Services.Diagnostics / TraceFilter.cs
blob88600604d7167cdeba31c1c4b7be1ce2ddfe7e51
1 //
2 // TraceFilter.cs: Internal generic (Input/Output) trace filter
3 //
4 // Author:
5 // Sebastien Pouliot (spouliot@motus.com)
6 //
7 // (C) 2003 Motus Technologies Inc. (http://www.motus.com)
8 //
10 using System;
11 using System.IO;
12 using System.Reflection;
13 using System.Xml;
15 namespace Microsoft.Web.Services.Diagnostics {
17 internal class TraceFilter {
19 public static string GetCompleteFilename (string filename)
21 return AppDomain.CurrentDomain.BaseDirectory + Path.DirectorySeparatorChar + filename;
24 public static void WriteEnvelope (string filename, SoapEnvelope envelope)
26 if (envelope == null)
27 throw new ArgumentNullException ("envelope");
29 FileStream fs = null;
30 XmlDocument log = null;
31 try {
32 // load and lock xml document
33 if (!File.Exists (filename)) {
34 fs = File.Open (filename, FileMode.Create, FileAccess.Write, FileShare.Read);
35 log = new XmlDocument ();
36 log.LoadXml (String.Format ("<?xml version=\"1.0\" encoding=\"utf-8\"?>{0}<log/>", Environment.NewLine));
38 else {
39 fs = File.Open (filename, FileMode.Open, FileAccess.ReadWrite, FileShare.Read);
40 log = new XmlDocument ();
41 log.Load (fs);
43 // add new entry
44 XmlNode xn = log.ImportNode (envelope.DocumentElement, true);
45 log.DocumentElement.AppendChild (xn);
46 fs.Position = 0;
47 log.Save (fs);
49 finally {
50 fs.Close ();