温馨提示:代码在线浏览功能只能做为源码浏览参考,不能展示项目的全部,如果想更进一步了解该代码请下载:NETCMSv1.5(Build0509)完整源码版
当前文件路径:NetCMSv15/NetCMS.Content/Common/FsLog.cs

1//====================================================== 2
//== (c)2008 aspxcms inc by NeTCMS v1.0 == 3
//== Forum:bbs.aspxcms.com == 4
//== Website:www.aspxcms.com == 5
//====================================================== 6
using System; 7
using System.Collections.Generic; 8
using System.IO; 9
using System.Web; 10
using System.Text; 11
12
namespace NetCMS.Content.Common 13
{ 14
public class FsLog 15
{ 16
/// <summary> 17
/// 系统日志处理 18
/// </summary> 19
/// <param name="logt">日志类别 0常规日志 1异常日志</param> 20
/// <param name="logip">用户ip地址</param> 21
/// <param name="url">错误地址</param> 22
/// <param name="detail">日志内容</param> 23
public static void logSave(int logt, string logip, string url, string detail) 24
{ 25
StreamWriter sw = null; 26
DateTime date = DateTime.Now; 27
CommStr str = new CommStr(); 28
string FileName = date.Year + "-" + date.Month; 29
try 30
{ 31
检测日志目录是否存在 35
switch (logt) 36
{ 37
case 0: 38
FileName = HttpContext.Current.Server.MapPath("~/Logs/") + FileName + "-" + NetCMS.Common.Input.MD5(FileName + "~") + "-s.log"; 39
break; 40
case 1: 41
FileName = HttpContext.Current.Server.MapPath("~/Logs/") + FileName + "-" + NetCMS.Common.Input.MD5(FileName + "~") + "-e.log"; 42
break; 43
default: 44
FileName = HttpContext.Current.Server.MapPath("~/Logs/") + FileName + "-" + NetCMS.Common.Input.MD5(FileName + "~") + "-s.log"; 45
break; 46
} 47
检测日志文件是否存在 55
56
向log文件中写数相关日志 66
} 67
catch (Exception e) 68
{ 69
throw e; 70
} 71
finally 72
{ 73
if (sw != null) 74
sw.Close(); 75
} 76
} 77
78
79
/// <summary> 80
/// SaveUserLogs 写入日志 81
/// </summary> 82
/// <param name="intnum">类型,0为会员日志,1为管理员日志</param> 83
/// <param name="intSaveFiles">保存类型,0为只保存到数据库中,1保存到数据库和日志文件中</param> 84
/// <param name="titlestr">传入的日志标题</param> 85
/// <param name="ContentStr">传入的日志详细描述</param> 86
87
public static void SaveUserLogs(int intnum, int intSaveFiles, string titlestr, string ContentStr) 88
{ 89
NetCMS.DALFactory.INTLog fslog = NetCMS.DALFactory.DataAccess.CreateNTLog(); 90
int flag = fslog.Add(intnum, titlestr, ContentStr, HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString(), HttpContext.Current.Session["UserNum"].ToString(), HttpContext.Current.Session["SiteID"].ToString()); 91
if (flag < 1) 92
{ 93
throw new Exception("意外错误:未知错误!"); 94
} 95
else 96
{ 97
if (intSaveFiles == 1) 98
{ 99
StreamWriter sw = null; 100
DateTime date = DateTime.Now; 101
CommStr str = new CommStr(); 102
string FileName = date.Year + "-" + date.Month; 103
try 104
{ 105
FileName = HttpContext.Current.Server.MapPath("~/Logs/User-" + intnum + "-") + FileName + "-" + NetCMS.Common.Input.MD5(FileName + "~") + "-s.log"; 106
107
检测日志目录是否存在 120
121
sw.WriteLine("IP :" + HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"] + "\r"); 122
sw.WriteLine("title :" + titlestr + "\r"); 123
sw.WriteLine("content :" + ContentStr); 124
sw.WriteLine("usernum :" + HttpContext.Current.Session["UserNum"] + "|||SiteID:" + HttpContext.Current.Session["SiteID"]); 125
sw.WriteLine("Time :" + System.DateTime.Now); 126
sw.WriteLine("≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡≡\r"); 127
sw.Flush(); 128
} 129
finally 130
{ 131
if (sw != null) 132
sw.Close(); 133
} 134
} 135
} 136
} 137
} 138
} 139





}