|
|
|
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 static void WriteSql(string path, string content)
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
if (!Directory.Exists(path))
|
|
|
|
{
|
|
|
|
Directory.CreateDirectory(path);
|
|
|
|
}
|
|
|
|
string fileName = $"{path}//{DateTime.Now:yyyyMMdd}.log";
|
|
|
|
using (var sw = new StreamWriter(fileName, true, Encoding.Unicode))
|
|
|
|
{
|
|
|
|
sw.WriteLine($"{DateTime.Now:HH:mm:ss fff}\t{content}");
|
|
|
|
sw.WriteLine($"-----------------------------------------{Environment.NewLine}");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
catch (Exception ex)
|
|
|
|
{
|
|
|
|
string exMsg = ex.ToString();
|
|
|
|
//MessageBox.Show(ex.ToString());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public enum LogType
|
|
|
|
{
|
|
|
|
Debug,
|
|
|
|
Info,
|
|
|
|
Error
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public static Exception GetExceptionMessage(this Exception ex)
|
|
|
|
{
|
|
|
|
if (ex.InnerException == null) return ex;
|
|
|
|
return ex.InnerException.GetExceptionMessage();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|