12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- namespace DllFileSoc
- {
- class LogBLL
- {
- //public static readonly object objLock = new object();
- public static void Err(string msg, Exception ex)
- {
- string s = "err:" + msg + ":" + ex.Message;
- string filepathname = AppDomain.CurrentDomain.BaseDirectory + "socketlog";
- string filename = filepathname + "\\" + DateTime.Now.ToString("yyyy-MM-dd HH") + ".txt";
- if (!Directory.Exists(filepathname))//验证路径是否存在
- {
- Directory.CreateDirectory(filepathname);
- //不存在则创建
- }
- FileStream fs;
- StreamWriter sw;
- if (File.Exists(filename))
- //验证文件是否存在,有则追加,无则创建
- {
- fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
- }
- else
- {
- fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
- }
- sw = new StreamWriter(fs);
- //sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") );
- sw.WriteLine(s);
- sw.WriteLine("time:" + DateTime.Now.ToString());
- sw.WriteLine("----------------------------------");
-
- sw.Close();
- fs.Close();
- }
- public static void Err(string msg)
- {
- string s = "Msg:" + msg ;
- string filepathname = AppDomain.CurrentDomain.BaseDirectory + "socketlog";
- string filename = filepathname + "\\" + DateTime.Now.ToString("yyyy-MM-dd HH") + ".txt";
- if (!Directory.Exists(filepathname))//验证路径是否存在
- {
- Directory.CreateDirectory(filepathname);
- //不存在则创建
- }
- FileStream fs;
- StreamWriter sw;
- if (File.Exists(filename))
- //验证文件是否存在,有则追加,无则创建
- {
- fs = new FileStream(filename, FileMode.Append, FileAccess.Write);
- }
- else
- {
- fs = new FileStream(filename, FileMode.Create, FileAccess.Write);
- }
- sw = new StreamWriter(fs);
- //sw.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH-mm-ss") );
- sw.WriteLine(s);
- sw.WriteLine("time:" + DateTime.Now.ToString());
- sw.WriteLine("----------------------------------");
-
- sw.Close();
- fs.Close();
- }
- }
- }
|