/*
Media File XStream, Network file stream server supporting XBMSP
Copyright (C) 2004 j3g
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
This project can be found on SourceForge.
http://sourceforge.net/projects/mfxstream
*/
using System;
using System.IO;
namespace MediaStream{
/// <summary>
///
/// </summary>
public class CLogFile
{
private static String _strLogFile;
static CLogFile()
{
NewLogFile();
}
public static void NewLogFile()
{
if (!System.IO.Path.IsPathRooted(CSettings.GetLogFileName))
_strLogFile = CSettings.GetAppPath + "\\" + CSettings.GetLogFileName;
else
_strLogFile = CSettings.GetLogFileName;
if (System.IO.Path.IsPathRooted(_strLogFile))
{
if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(_strLogFile)))
System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(_strLogFile));
}
}
// public static void NewLogLevel()
// {
// if (LogLevel.NoLoging == m_nLogLevel)
// {
// m_strLogFile = CSettings.GetLogFileName;
// if (System.IO.Path.IsPathRooted(m_strLogFile))
// {
// if (!System.IO.Directory.Exists(System.IO.Path.GetDirectoryName(m_strLogFile)))
// System.IO.Directory.CreateDirectory(System.IO.Path.GetDirectoryName(m_strLogFile));
// }
// }
// m_nLogLevel = CSettings.GetLogLevel;
// }
public static void Log(String Message, String Source, LogLevel Level)
{
if (Level <= CSettings.GetLogLevel)
{
try
{
TextWriter twLogFile;
String strLine = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss:ff") + ":";
strLine += Source + ":" + Level + ":" + Message;
twLogFile = TextWriter.Synchronized(File.AppendText(_strLogFile));
twLogFile.WriteLine(strLine);
twLogFile.Flush();
twLogFile.Close();
}
catch
{
}
}
}
}
public enum LogLevel
{
NoLoging = 0,
FatalError = 10,
Error = 20,
Warning = 30,
Information = 40,
DebugLevel1 = 50,
DebugLevel2 = 60
}
}
|