1234567891011121314151617181920212223242526272829303132333435363738394041 |
- using System;
- using System.IO;
- using System.Text;
- using System.Windows.Forms;
- namespace prBrowser
- {
- public class Log
- {
- public static void LogInfo(string logInput, string directory)
- {
- string spcfolder = Application.StartupPath;
- spcfolder = spcfolder.Replace("\\", "/");
- string nowData = DateTime.Now.ToString("yyyy-MM-dd");
- nowData = nowData.Replace("-", null);
- //QY 搜索文件路径中是否存在所需文件夹,不存在则创建
- if (!string.IsNullOrWhiteSpace(spcfolder))
- {
- if (!Directory.Exists(spcfolder + "/service/"))
- {
- //Directory.CreateDirectory(spcfolder + "/service/");
- Directory.CreateDirectory(spcfolder + "/service/log");
- }
- else if (!Directory.Exists(spcfolder + "/service/log/"))
- {
- Directory.CreateDirectory(spcfolder + "/service/log");
- }
- }
- string inputDir = spcfolder + "/service/log/" + directory + nowData + ".txt";
- FileStream fileStreamObj = new FileStream(inputDir, FileMode.Append, FileAccess.Write);
- string localDateTime = DateTime.Now.ToLocalTime().ToString();
- logInput = localDateTime + ": " + logInput + "\r\n";
- byte[] data = Encoding.Default.GetBytes(logInput);
- fileStreamObj.Write(data, 0, data.Length);
- fileStreamObj.Flush();
- fileStreamObj.Close();
- }
- }
- }
|