public static void WriteLog(String log)
if (!Directory.Exists(FileDir)) Directory.CreateDirectory(FileDir);
string FileName = FileDir + DateTime.Now.ToString("yyyy-MM-dd HH") + ".txt";
FileName = FileName.Remove(0, 1);// FileName.Substring(1, FileName.Length);
// MessageBox.Show(FileName);
try
{
using (StreamWriter sw = File.AppendText(FileName))
{
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff") + " --> " + log);
}
}
catch (Exception ex)
{
MessageBox.Show("写条码配置文件有问题!" + ex.Message, "ScanBarcode");
}
}
{
//在CE中获取程序所在目录
string FileDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().GetName().CodeBase) + "\\log\\";if (!Directory.Exists(FileDir)) Directory.CreateDirectory(FileDir);
string FileName = FileDir + DateTime.Now.ToString("yyyy-MM-dd HH") + ".txt";
FileName = FileName.Remove(0, 1);// FileName.Substring(1, FileName.Length);
// MessageBox.Show(FileName);
try
{
using (StreamWriter sw = File.AppendText(FileName))
{
sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.ffff") + " --> " + log);
}
}
catch (Exception ex)
{
MessageBox.Show("写条码配置文件有问题!" + ex.Message, "ScanBarcode");
}
}