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.
43 lines
1.2 KiB
43 lines
1.2 KiB
using System;
|
|
using System.IO;
|
|
using System.Text;
|
|
|
|
namespace QMAPP.WinForm
|
|
{
|
|
public static class LogHelper
|
|
{
|
|
public static readonly string LogPath = $"{IoHelper.GetDllPath()}//Logs";
|
|
|
|
public static void Write(string content, string path = null)
|
|
{
|
|
try
|
|
{
|
|
if (path == null)
|
|
path = LogPath;
|
|
if (!Directory.Exists(path))
|
|
{
|
|
Directory.CreateDirectory(path);
|
|
}
|
|
string filename = $"{path}//{DateTime.Now:yyyyMMdd}.log";
|
|
StreamWriter sw = new StreamWriter(filename, true, Encoding.Unicode);
|
|
sw.WriteLine($"{DateTime.Now:HH:mm:ss fff}\t{content}");
|
|
sw.WriteLine($"-----------------------------------------{Environment.NewLine}");
|
|
sw.Close();
|
|
}
|
|
catch (Exception)
|
|
{
|
|
// MessageBox.Show(ex.ToString());
|
|
}
|
|
}
|
|
|
|
public static void WriteEx(Exception ex)
|
|
{
|
|
Write(ex.ToString());
|
|
}
|
|
|
|
public static void WriteEx(Exception ex, string path)
|
|
{
|
|
Write(ex.ToString(), path);
|
|
}
|
|
}
|
|
}
|