137 lines
3.5 KiB
C#
137 lines
3.5 KiB
C#
///#################################################################
|
|
/// 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;
|
|
|
|
using Gtk;
|
|
|
|
class Logger
|
|
{
|
|
private static string debugLog = null;
|
|
private static Stream debugStream= null;
|
|
private static Mutex dbgmutex = new Mutex();
|
|
|
|
static Gtk.TreeStore tsLog;
|
|
|
|
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 ActivateLogWindow(Gtk.TreeView tvLog)
|
|
{
|
|
tsLog = new TreeStore(typeof(string));
|
|
tvLog.Model = tsLog;
|
|
}
|
|
|
|
public static void StopLogWindow()
|
|
{
|
|
tsLog = null;
|
|
}
|
|
|
|
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 (tsLog != null)
|
|
{
|
|
tsLog.AppendValues(DateTime.Now.ToLongTimeString()
|
|
+ ":"
|
|
+ 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 (tsLog != null)
|
|
{
|
|
tsLog.AppendValues(DateTime.Now.ToLongTimeString()
|
|
+ ": Exception encountered - ");
|
|
tsLog.AppendValues(message);
|
|
|
|
StackTrace st1 = new StackTrace();
|
|
tsLog.AppendValues(st1.ToString());
|
|
}
|
|
|
|
#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"));
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|