2005-10-11 21:51:00 +02:00
|
|
|
///#################################################################
|
|
|
|
/// 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;
|
|
|
|
|
2005-10-31 21:24:36 +01:00
|
|
|
using Gtk;
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
class Logger
|
|
|
|
{
|
|
|
|
private static string debugLog = null;
|
|
|
|
private static Stream debugStream= null;
|
|
|
|
private static Mutex dbgmutex = new Mutex();
|
2005-10-31 21:24:36 +01:00
|
|
|
|
|
|
|
static Gtk.TreeStore tsLog;
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
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
|
|
|
|
}
|
|
|
|
|
2005-10-31 21:24:36 +01:00
|
|
|
|
|
|
|
public static void ActivateLogWindow(Gtk.TreeView tvLog)
|
|
|
|
{
|
|
|
|
tsLog = new TreeStore(typeof(string));
|
|
|
|
tvLog.Model = tsLog;
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void StopLogWindow()
|
|
|
|
{
|
|
|
|
tsLog = null;
|
|
|
|
}
|
2005-10-11 21:51:00 +02:00
|
|
|
|
|
|
|
public static void logbreak()
|
|
|
|
{
|
|
|
|
dbgmutex.WaitOne();
|
|
|
|
Debug.WriteLine(" ") ;
|
|
|
|
Debug.WriteLine("----------------------------------------------------") ;
|
|
|
|
Debug.WriteLine(" ") ;
|
2005-10-31 21:24:36 +01:00
|
|
|
dbgmutex.ReleaseMutex();
|
2005-10-11 21:51:00 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// The log format is Time stamp :Component name: Error description
|
|
|
|
public static void DbgLog(string message)
|
2005-10-31 21:24:36 +01:00
|
|
|
{
|
|
|
|
if (tsLog != null)
|
|
|
|
{
|
|
|
|
tsLog.AppendValues(DateTime.Now.ToLongTimeString()
|
|
|
|
+ ":"
|
|
|
|
+ message);
|
|
|
|
}
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
#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)
|
|
|
|
{
|
2005-10-31 21:24:36 +01:00
|
|
|
if (tsLog != null)
|
|
|
|
{
|
|
|
|
tsLog.AppendValues(DateTime.Now.ToLongTimeString()
|
|
|
|
+ ": Exception encountered - ");
|
|
|
|
tsLog.AppendValues(message);
|
|
|
|
|
|
|
|
StackTrace st = new StackTrace();
|
|
|
|
tsLog.AppendValues(st.ToString());
|
|
|
|
}
|
|
|
|
|
2005-10-11 21:51:00 +02:00
|
|
|
#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"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|