网站错误获取 网站准备放外网了。我怕代码中有错误。请问怎么获取网站错误。然后插入数据库。让我查看方便修改。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 写个错误日志http://www.cnblogs.com/ringwang/archive/2007/12/12/992023.html 这个是把错误信息保存到Xml文件中的,可以改一下保存到数据库中WebLogs.csusing System;using System.Data;using System.Data.SqlClient;using System.IO;using System.Xml;namespace Wg{ /// <summary> /// WebLogs 的摘要说明。 /// </summary> public class WebLogs { private string logPath = string.Empty; public WebLogs(string LogPath) { // // TODO: 在此处添加构造函数逻辑 // logPath = LogPath; } public string FloderPath { get { return logPath; } set { logPath = value; } } public void Add(string Content,string IP,string Agent,string Url,string UrlReferrer,string SessionXML) { string filename = DateTime.Now.ToShortDateString()+".xml"; string filepath = logPath + filename; LogWrite(filepath,Content,IP,Agent,Url,UrlReferrer,SessionXML); } private void LogWrite(string filepath,string Content,string IP,string Agent,string Url,string UrlReferrer,string SessionXML) { XmlDocument xdoc = new XmlDocument(); if(!File.Exists(filepath)) { xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+ "<item></item>"); } else { xdoc.Load(filepath); } XmlDocument xmldoc = new XmlDocument(); xmldoc.LoadXml(SessionXML); XmlElement root = xmldoc.DocumentElement; // 创建一个新的日志节点并将它添加到根节点下 XmlElement parentNode = xdoc.CreateElement("ErrorLog"); xdoc.DocumentElement.PrependChild(parentNode); // 创建所有用于存储信息的节点 XmlElement timeNode = xdoc.CreateElement("Time"); XmlElement ipNode = xdoc.CreateElement("IP"); XmlElement agentNode = xdoc.CreateElement("Agent"); XmlElement urlNode = xdoc.CreateElement("Url"); XmlElement referrerNode = xdoc.CreateElement("Referrer"); XmlElement sessionXML = xdoc.CreateElement("sessionXML"); // 获取文本信息 XmlText timeText = xdoc.CreateTextNode(DateTime.Now.ToString()); XmlText ipText = xdoc.CreateTextNode(IP); XmlText agentText = xdoc.CreateTextNode(Agent); XmlText urlText = xdoc.CreateTextNode(Url); XmlText referrerText = xdoc.CreateTextNode(UrlReferrer); XmlText sessionText = xdoc.CreateTextNode(SessionXML); // 将上面创建的各个存储信息的节点添加到guest节点下但并不包含最终的值 parentNode.AppendChild(timeNode); parentNode.AppendChild(ipNode); parentNode.AppendChild(agentNode); parentNode.AppendChild(urlNode); parentNode.AppendChild(referrerNode); parentNode.AppendChild(sessionXML); // 将上面获取的文本信息添加到与之相对应的节点中 timeNode.AppendChild(timeText); ipNode.AppendChild(ipText); agentNode.AppendChild(agentText); urlNode.AppendChild(urlText); referrerNode.AppendChild(referrerText); sessionXML.AppendChild(sessionText); // 保存存储信息的XML文件 xdoc.Save(filepath); xdoc = null; } }}Global.asax.cs protected void Session_Start(Object sender, EventArgs e) { WebVisitor visitor = new WebVisitor(Server.MapPath(null).Substring(0,Server.MapPath(null).ToLower().LastIndexOf("wg")+2)+"//logs//count.xml"); visitor.addCount(); } protected void Application_Error(Object sender, EventArgs e) { WebLogs Logs = new WebLogs(Server.MapPath(null).Substring(0,Server.MapPath(null).ToLower().LastIndexOf("wg")+2)+"//logs/"); string SessionXML = this.Session["xml"].ToString(); //string SessionXML = Server.MapPath(null).Substring(0,Server.MapPath(null).ToLower().LastIndexOf("wg")+2)+"//temp/"+this.Session["xml"]+".xml"; string referrerUri = (Request.UrlReferrer != null) ? Request.UrlReferrer.AbsoluteUri : string.Empty; Logs.Add(Server.GetLastError().ToString(),Request.UserHostAddress,Request.UserAgent,Request.Url.AbsoluteUri,referrerUri,SessionXML); Server.Transfer("../Error.aspx"); } Application_Error(object sender, EventArgs e) 中把错误写入磁盘 外挂个webserveice来接受错误数据。 Application_Error(object sender, EventArgs e) 恩,在这个glob.asx文件方法中确实可以捕获你这个站点的所有错误 我这个存储过程哪里有问题哇? 返回不了数据挖 关于C#遍历文件夹和文件的问题 Replace字符串的时候,字符串是一个地址,单斜杠怎么处理? Repeater 无记录时 怎么用asp.net实现服务器的sqlserver2000数据库备份并下载到本地的pc上? 在.net中如何修改数据库中的值 今天申请了2个免费空间,爽。 iis重定向URL 去掉gridview左右的边框 我是新手,简单的问题,请帮忙! 如何在提交了新的话题后,页面上话题选项右边会显示NEW图标,而用户点击话题选项进入话题列表后NEW图标消失 Datalist问题
http://www.cnblogs.com/ringwang/archive/2007/12/12/992023.html
WebLogs.csusing System;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using System.Xml;namespace Wg
{
/// <summary>
/// WebLogs 的摘要说明。
/// </summary>
public class WebLogs
{
private string logPath = string.Empty; public WebLogs(string LogPath)
{
//
// TODO: 在此处添加构造函数逻辑
//
logPath = LogPath;
} public string FloderPath
{
get
{
return logPath;
}
set
{
logPath = value;
}
} public void Add(string Content,string IP,string Agent,string Url,string UrlReferrer,string SessionXML)
{
string filename = DateTime.Now.ToShortDateString()+".xml";
string filepath = logPath + filename;
LogWrite(filepath,Content,IP,Agent,Url,UrlReferrer,SessionXML);
} private void LogWrite(string filepath,string Content,string IP,string Agent,string Url,string UrlReferrer,string SessionXML)
{
XmlDocument xdoc = new XmlDocument();
if(!File.Exists(filepath))
{
xdoc.LoadXml("<?xml version=\"1.0\" encoding=\"utf-8\"?>"+
"<item></item>");
}
else
{
xdoc.Load(filepath);
} XmlDocument xmldoc = new XmlDocument();
xmldoc.LoadXml(SessionXML);
XmlElement root = xmldoc.DocumentElement; // 创建一个新的日志节点并将它添加到根节点下
XmlElement parentNode = xdoc.CreateElement("ErrorLog");
xdoc.DocumentElement.PrependChild(parentNode);
// 创建所有用于存储信息的节点
XmlElement timeNode = xdoc.CreateElement("Time");
XmlElement ipNode = xdoc.CreateElement("IP");
XmlElement agentNode = xdoc.CreateElement("Agent");
XmlElement urlNode = xdoc.CreateElement("Url");
XmlElement referrerNode = xdoc.CreateElement("Referrer");
XmlElement sessionXML = xdoc.CreateElement("sessionXML");
// 获取文本信息
XmlText timeText = xdoc.CreateTextNode(DateTime.Now.ToString());
XmlText ipText = xdoc.CreateTextNode(IP);
XmlText agentText = xdoc.CreateTextNode(Agent);
XmlText urlText = xdoc.CreateTextNode(Url);
XmlText referrerText = xdoc.CreateTextNode(UrlReferrer);
XmlText sessionText = xdoc.CreateTextNode(SessionXML);
// 将上面创建的各个存储信息的节点添加到guest节点下但并不包含最终的值
parentNode.AppendChild(timeNode);
parentNode.AppendChild(ipNode);
parentNode.AppendChild(agentNode);
parentNode.AppendChild(urlNode);
parentNode.AppendChild(referrerNode);
parentNode.AppendChild(sessionXML);
// 将上面获取的文本信息添加到与之相对应的节点中
timeNode.AppendChild(timeText);
ipNode.AppendChild(ipText);
agentNode.AppendChild(agentText);
urlNode.AppendChild(urlText);
referrerNode.AppendChild(referrerText);
sessionXML.AppendChild(sessionText); // 保存存储信息的XML文件
xdoc.Save(filepath);
xdoc = null;
}
}
}Global.asax.cs protected void Session_Start(Object sender, EventArgs e)
{
WebVisitor visitor = new WebVisitor(Server.MapPath(null).Substring(0,Server.MapPath(null).ToLower().LastIndexOf("wg")+2)+"//logs//count.xml");
visitor.addCount();
} protected void Application_Error(Object sender, EventArgs e)
{
WebLogs Logs = new WebLogs(Server.MapPath(null).Substring(0,Server.MapPath(null).ToLower().LastIndexOf("wg")+2)+"//logs/");
string SessionXML = this.Session["xml"].ToString();
//string SessionXML = Server.MapPath(null).Substring(0,Server.MapPath(null).ToLower().LastIndexOf("wg")+2)+"//temp/"+this.Session["xml"]+".xml";
string referrerUri = (Request.UrlReferrer != null) ? Request.UrlReferrer.AbsoluteUri : string.Empty;
Logs.Add(Server.GetLastError().ToString(),Request.UserHostAddress,Request.UserAgent,Request.Url.AbsoluteUri,referrerUri,SessionXML); Server.Transfer("../Error.aspx");
}
中把错误写入磁盘