public void myLog(string format, params object[] arg)
{
myLog(string.Format(format, arg));
}
/// <summary> log寫入text檔案 </summary>
/// <param name="message"></param>
public void myLog(string message)
{
//取得執行檔案(BIN/DEBUG)的路徑,加上LOG資料夾形成完整路徑
string loaclpath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string path = Path.Combine(Path.GetFullPath(loaclpath), "log");
if (string.IsNullOrEmpty(path))
{
path = Directory.GetCurrentDirectory();
}
string filename = Path.Combine(path, string.Format("{0:yyyy}\\{0:MM}\\{0:yyyy-MM-dd}.txt", DateTime.Now));
FileInfo finfo = new FileInfo(filename);
if (finfo.Directory.Exists == false)
{
finfo.Directory.Create();
}
string writeString = string.Format("[{0:yyyy/MM/dd HH:mm:ss}] {1}",
DateTime.Now, message) + Environment.NewLine;
File.AppendAllText(filename, writeString, Encoding.Unicode);
}
{
myLog(string.Format(format, arg));
}
/// <summary> log寫入text檔案 </summary>
/// <param name="message"></param>
public void myLog(string message)
{
//取得執行檔案(BIN/DEBUG)的路徑,加上LOG資料夾形成完整路徑
string loaclpath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location);
string path = Path.Combine(Path.GetFullPath(loaclpath), "log");
if (string.IsNullOrEmpty(path))
{
path = Directory.GetCurrentDirectory();
}
string filename = Path.Combine(path, string.Format("{0:yyyy}\\{0:MM}\\{0:yyyy-MM-dd}.txt", DateTime.Now));
FileInfo finfo = new FileInfo(filename);
if (finfo.Directory.Exists == false)
{
finfo.Directory.Create();
}
string writeString = string.Format("[{0:yyyy/MM/dd HH:mm:ss}] {1}",
DateTime.Now, message) + Environment.NewLine;
File.AppendAllText(filename, writeString, Encoding.Unicode);
}
沒有留言:
張貼留言