|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 |
private
static void Write(string
sMsg, string
fileName) { if
(sMsg != "") { try { var
dir = new
FileInfo(Assembly.GetEntryAssembly().Location).DirectoryName + "\\log\\"; if
(!Directory.Exists(dir)) { Directory.CreateDirectory(dir); } var
fi =new
FileInfo( dir + fileName+".log"); if
(!fi.Exists) { using
(var
sw = fi.CreateText()) { sw.WriteLine(DateTime.Now + ": "
+ sMsg + "\n"); sw.Close(); } } else { using
(var
sw = fi.AppendText()) { sw.WriteLine(DateTime.Now + ": "
+ sMsg + "\n"); sw.Close(); } } } catch
(Exception ex) { Console.WriteLine(ex.Message); } } } |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 |
public
static bool Reset() { try { lock
(_readWriteLock) { var
fi = new
FileInfo("Data/ValidTickets_bak.xml"); fi.CopyTo(_xmlFileName, true); } } catch
(Exception ex) { Logger.WriteLogger(ex, ConstValues.MainLogFileName); return
false; } return
true; } |
文件写操作--WriteLog,布布扣,bubuko.com
原文:http://www.cnblogs.com/cw_volcano/p/3597438.html