1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- using System;
- using System.Collections.Generic;
- using System.IO;
- using System.Text;
- namespace DllFileSoc
- {
- public class LogBLL
- {
- //public static readonly object objLock = new object();
- // Path.DirectorySeparatorChar: '\'
- // Path.AltDirectorySeparatorChar: '/'正斜杠 (/) 字符。 它是 Unix 系统上唯一可识别的目录分隔符
- public static void Err(string msg, Exception ex)
- {
- string s = "err:" + msg + ":" + ex.Message;
- //string filepathname = AppDomain.CurrentDomain.BaseDirectory + "socketlog";
- string filepathname = DllPubInfo.PubInfo.LogPath;
- string filename = filepathname + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd") + ".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)
- {
- try
- {
- string s = "Msg:" + msg;
- //string filepathname = AppDomain.CurrentDomain.BaseDirectory + "socketlog";
- string filepathname = DllPubInfo.PubInfo.LogPath;
- string filename = filepathname + Path.DirectorySeparatorChar + DateTime.Now.ToString("yyyy-MM-dd") + ".txt";
- if (!Directory.Exists(filepathname))//验证路径是否存在
- {
- Directory.CreateDirectory(filepathname);
- //不存在则创建
- }
- FileStream fs;
- StreamWriter sw;
- if (File.Exists(filename))
- //验证文件是否存在,有则追加,无则创建
- {
- fs = new FileStream(filename, FileMode.Append, FileAccess.Write,FileShare.ReadWrite);
- }
- 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();
- }
- catch
- {
- }
- }
- }
- }
|