Public class LogManager
{
Private static string logPath = string. Empty;
/// <Summary>
/// Folder for saving logs
/// </Summary>
Public static string LogPath
{
Get
{
If (logPath = string. Empty)
{
If (System. Web. HttpContext. Current = null)
// Windows Forms Application
LogPath = AppDomain. CurrentDomain. BaseDirectory;
Else
// Web application
LogPath = AppDomain. CurrentDomain. BaseDirectory + @ "bin ";
}
Return logPath;
}
Set {logPath = value ;}
}
Private static string logFielPrefix = string. Empty;
/// <Summary>
/// Log File prefix
/// </Summary>
Public static string LogFielPrefix
{
Get {return logFielPrefix ;}
Set {logFielPrefix = value ;}
}
/// <Summary>
/// Write logs
/// </Summary>
Public static void WriteLog (string logFile, string msg)
{
Try
{
System. IO. StreamWriter sw = System. IO. File. AppendText (
LogPath + LogFielPrefix + logFile + "" +
DateTime. Now. ToString ("yyyyMMdd") + ". Log"
);
Sw. WriteLine (DateTime. Now. ToString ("yyyy-MM-dd HH: mm: ss:") + msg );
Sw. Close ();
}
Catch
{}
}
/// <Summary>
/// Write logs
/// </Summary>
Public static void WriteLog (LogFile logFile, string msg)
{
WriteLog (logFile. ToString (), msg );
}
}
/// <Summary>
/// Log Type
/// </Summary>
Public enum LogFile
{
Trace,
Warning,
Error,
SQL
}