You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
114 lines
3.3 KiB
114 lines
3.3 KiB
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
using System.Windows.Forms;
|
|
|
|
namespace CK.SCP.Utils
|
|
{
|
|
public static class LogHelper
|
|
{
|
|
|
|
public static string Path = "";
|
|
|
|
public static void Write(string path, string content)
|
|
{
|
|
try
|
|
{
|
|
|
|
var strPath = IoHelper.GetDllPath() + "//"+path;
|
|
if (!Directory.Exists(strPath))
|
|
{
|
|
Directory.CreateDirectory(strPath);
|
|
}
|
|
string filename = string.Concat(new[]
|
|
{
|
|
strPath,
|
|
"//",
|
|
DateTime.Now.ToLongDateString(),
|
|
".txt"
|
|
});
|
|
StreamWriter sw = new StreamWriter(filename, true, Encoding.Unicode);
|
|
sw.WriteLine(DateTime.Now.ToString("yyyyMMdd"));
|
|
sw.WriteLine(content);
|
|
// sw.WriteLine("-------------------------------------");
|
|
sw.Close();
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString());
|
|
}
|
|
}
|
|
|
|
|
|
public static void Write(string content)
|
|
{
|
|
try
|
|
{
|
|
|
|
Path = IoHelper.GetDllPath() + "//Logs";
|
|
if (!Directory.Exists(Path))
|
|
{
|
|
Directory.CreateDirectory(Path);
|
|
}
|
|
string filename = string.Concat(new[]
|
|
{
|
|
Path,
|
|
"//",
|
|
DateTime.Now.ToLongDateString(),
|
|
".txt"
|
|
});
|
|
StreamWriter sw = new StreamWriter(filename, true, Encoding.Unicode);
|
|
sw.WriteLine(DateTime.Now.ToString("HH:mm:ss fff")+"\t"+content);
|
|
// sw.WriteLine("-------------------------------------");
|
|
sw.Close();
|
|
}
|
|
catch(Exception ex)
|
|
{
|
|
MessageBox.Show(ex.ToString());
|
|
}
|
|
}
|
|
|
|
public static void WriteEx(Exception ex)
|
|
{
|
|
Write(ex.ToString());
|
|
}
|
|
|
|
public readonly static log4net.ILog _logInfo = log4net.LogManager.GetLogger("Info");
|
|
public readonly static log4net.ILog _logDebug = log4net.LogManager.GetLogger("Debug");
|
|
public readonly static log4net.ILog _logError = log4net.LogManager.GetLogger("Error");
|
|
|
|
public static void Writlog(LogType p_logtype, Type p_type, string p_methodName, string p_msg)
|
|
{
|
|
|
|
switch (p_logtype)
|
|
{
|
|
case LogType.Error:
|
|
_logError.ErrorFormat("{0}.{1}:{2}", p_type.FullName, p_methodName, p_msg);
|
|
break;
|
|
case LogType.Info:
|
|
_logInfo.InfoFormat("{0}.{1}:{2}", p_type.FullName, p_methodName, p_msg);
|
|
break;
|
|
|
|
case LogType.Debug:
|
|
_logDebug.DebugFormat("{0}.{1}:{2}", p_type.FullName, p_methodName, p_msg);
|
|
break;
|
|
}
|
|
}
|
|
public enum LogType
|
|
{
|
|
Debug,
|
|
Info,
|
|
Error
|
|
|
|
}
|
|
|
|
public static Exception GetExceptionMessage(this Exception ex)
|
|
{
|
|
if (ex.InnerException == null) return ex;
|
|
return ex.InnerException.GetExceptionMessage();
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|