///################################################################# /// PROJECT : CASA - Common Authentication Services Adapter /// FILE : Logger.cs /// DESCRIPTION : Debug Log implementation Class. /// AUTHORS : /// CREATED ON : /// UPDATED ON : ///################################################################# namespace Novell.CASA.GUI { using System; using System.Text; using System.Diagnostics; using System.IO; using System.Threading; class Logger { private static string debugLog = null; private static Stream debugStream= null; private static Mutex dbgmutex = new Mutex(); static Logger() { #if DEBUG debugLog = GetHomeDir() + "/.CASAManager.logs"; // Set up for Debug if( File.Exists( debugLog ) ) { File.Delete( debugLog ); } debugStream = File.Create(debugLog); Debug.Listeners.Add(new TextWriterTraceListener(debugStream)); Debug.AutoFlush = true; Debug.Indent(); Debug.WriteLine("Debug Log created"); #endif } public static void logbreak() { dbgmutex.WaitOne(); Debug.WriteLine(" ") ; Debug.WriteLine("----------------------------------------------------") ; Debug.WriteLine(" ") ; dbgmutex.ReleaseMutex(); } // The log format is Time stamp :Component name: Error description public static void DbgLog(string message) { #if DEBUG dbgmutex.WaitOne(); Debug.Write(DateTime.Now.ToLongTimeString()); Debug.Write(" " + DateTime.Now.ToLongDateString()); Debug.Write(":"); Debug.WriteLine(message); dbgmutex.ReleaseMutex(); #endif } public static void ExpLog(string message) { #if DEBUG dbgmutex.WaitOne(); Debug.Write(DateTime.Now.ToLongTimeString()); Debug.Write(" " + DateTime.Now.ToLongDateString()); Debug.Write(": Exception encountered - "); Debug.WriteLine(message); Debug.WriteLine(" ") ; StackTrace st = new StackTrace(); Debug.WriteLine(st.ToString()); dbgmutex.ReleaseMutex(); #endif } static string GetHomeDir() { int platform = (int)Environment.OSVersion.Platform; if ( (platform == 128) || ( platform == 4) ) { return System.Environment.GetEnvironmentVariable("HOME"); } else { return (System.Environment.GetEnvironmentVariable("HOMEDRIVE")) + (System.Environment.GetEnvironmentVariable("HOMEPATH")); } } } }