axiosengine/axios/Engine/Log/AxiosLog.cs

79 lines
2.2 KiB
C#
Raw Normal View History

2012-03-19 23:57:59 +00:00
using System;
using System.Collections.Generic;
using Axios.Engine.Data;
using Axios.Engine.File;
2012-03-19 23:57:59 +00:00
namespace Axios.Engine.Log
{
[Flags]
public enum LoggingFlag
{
NONE = 0,
DEBUG = 1,
INFO = 2,
WARN = 4,
ERROR = 8,
FATAL = 16,
ALL = ~0
2012-03-19 23:57:59 +00:00
}
public class AxiosLog : Singleton<AxiosLog>
{
private List<string> _log;
// Logs everything regardless of log level
// Used for debugging purposes
private List<string> _extendedlog;
2012-03-19 23:57:59 +00:00
public AxiosLog()
{
_log = new List<string>();
_extendedlog = new List<string>();
2012-03-19 23:57:59 +00:00
}
public void AddLine(string line, LoggingFlag flag)
{
if (Settings.Loglevel.HasFlag(flag))
{
AxiosCommandConsole c = (AxiosCommandConsole)Cache.Instance.get("commandconsole");
if (c != null)
c.AddToLog(line);
2012-03-19 23:57:59 +00:00
_log.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line);
}
_extendedlog.Add("[" + DateTime.Now.ToString("M/d/yyyy H:mm:ss") + " - " + flag.ToString() + "]" + line);
2012-03-19 23:57:59 +00:00
}
public List<string> GetLogList()
{
return _log;
}
public string GetLog(string seperator)
{
return String.Join(seperator, _log.ToArray()) + seperator;
}
public string GetLog()
{
return GetLog("\r\n");
}
public void writeLog()
{
using (AxiosRegularFile file = new AxiosRegularFile(System.IO.Directory.GetCurrentDirectory() + "/axioslog.log"))
{
file.WriteData(GetLog(), System.IO.FileMode.Create);
}
}
public void writeExtendedLog()
{
using (AxiosRegularFile file = new AxiosRegularFile(System.IO.Directory.GetCurrentDirectory() + "/axioslog.log"))
{
file.WriteData(String.Join("\r\n", _extendedlog.ToArray()), System.IO.FileMode.Create);
}
}
2012-03-19 23:57:59 +00:00
}
}