-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSystemError.cs
More file actions
60 lines (52 loc) · 1.36 KB
/
Copy pathSystemError.cs
File metadata and controls
60 lines (52 loc) · 1.36 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
using System;
using System.Collections.Generic;
using System.Web;
using System.IO;
using System.Web.UI;
+/*
2 +**功能:记录错误!
3 +**描述:当我们把程序封装好之后,别人就看不到调试的信息,我们只能生成到本地的文件里面。
4 +*/
namespace ElevatorWebServices
{
public class SystemError : Page
{
//记录错误日志位置
private static string _fileName = HttpContext.Current.Server.MapPath(@"~/LOG/Systemlog.txt");
public static String FileName
{
get
{
return(_fileName);
}
set
{
if(value != null || value != "")
{
_fileName = value;
}
}
}
/// <summary>
/// 记录日志至文本文件
/// </summary>
/// <param name="message">记录的内容</param>
public static void SystemLog(string message)
{
if (File.Exists(FileName))
{
///如果日志文件已经存在,则直接写入日志文件
StreamWriter sr = File.AppendText(FileName);
sr.WriteLine("\n");
sr.WriteLine(DateTime.Now.ToString() + message);
sr.Close();
}
else
{
///创建日志文件
StreamWriter sr = File.CreateText(FileName);
sr.Close();
}
}
}
}