diff --git a/c#/LogUtils.cs b/c#/LogUtils.cs new file mode 100644 index 0000000000000000000000000000000000000000..0389eadc5688c9a7754ff732129ef83fcec1b403 --- /dev/null +++ b/c#/LogUtils.cs @@ -0,0 +1,39 @@ +using System; + +namespace Grab +{ + public class LogUtils + { + /// + /// 本地log + /// + /// + /// + public static void WriteLog(String log, String type = "info") + { + try + { + string path = AppDomain.CurrentDomain.BaseDirectory + "/log/"; + DirectoryInfo info = new DirectoryInfo(path); + if (!info.Exists) { + info.Create(); + } + StreamWriter sw; + FileInfo fi = new FileInfo(path + type + "_" + DateTime.Now.ToString("yyyyMMdd") + ".log"); + if (!fi.Exists) { + sw = fi.CreateText(); + } else { + sw = File.AppendText(fi.FullName); + } + sw.WriteLine("================" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "================"); + sw.WriteLine(log); + sw.Close(); + sw.Dispose(); + } + catch (Exception e) + { + } + } + + } +}