////////////////////////////////////////////////////////////// /// <summary> /// This method is used to set the global trace file name /// for all objects. /// </summary> /// <param name="filename">the file name; if the name is "" or /// null, the Console.Error stream will be used</param> /// <param name="append">true to append to an existing /// file</param> ////////////////////////////////////////////////////////////// public static void SetTraceFile(string filename, bool append) { lock (_ts) { if (_ts != null) { _ts.Close(); } if ("" == filename || filename == null) { _ts = SystemTraceWriter.GetInstance(); return; } try { // make sure we expand any environment variables filename = Environment.ExpandEnvironmentVariables(filename); _ts = new FileTraceWriter(filename, append); _traceFileName = filename; } catch (Exception e) { _traceFileName = ""; Console.Error.WriteLine(e); _ts = SystemTraceWriter.GetInstance(); } } }
////////////////////////////////////////////////////////////// /// <summary> /// This is the singleton's factory method for creating or /// obtaining a reference. /// </summary> /// <returns>a reference to the shared trace writer /// instance</returns> ////////////////////////////////////////////////////////////// public static TraceWriter GetInstance() { if (_instance == null) { _instance = new SystemTraceWriter(); } return(_instance); }