惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

MyScale Blog
MyScale Blog
F
Full Disclosure
Microsoft Azure Blog
Microsoft Azure Blog
Jina AI
Jina AI
Recent Announcements
Recent Announcements
美团技术团队
L
LangChain Blog
P
Privacy & Cybersecurity Law Blog
M
MIT News - Artificial intelligence
www.infosecurity-magazine.com
www.infosecurity-magazine.com
W
WeLiveSecurity
Engineering at Meta
Engineering at Meta
S
Security @ Cisco Blogs
H
Hackread – Cybersecurity News, Data Breaches, AI and More
Exploit-DB.com RSS Feed
Exploit-DB.com RSS Feed
Help Net Security
Help Net Security
L
LINUX DO - 最新话题
S
Secure Thoughts
O
OpenAI News
Hacker News - Newest:
Hacker News - Newest: "LLM"
A
About on SuperTechFans
NISL@THU
NISL@THU
C
Cyber Attacks, Cyber Crime and Cyber Security
Cyberwarzone
Cyberwarzone
T
Tailwind CSS Blog
T
The Blog of Author Tim Ferriss
Recent Commits to openclaw:main
Recent Commits to openclaw:main
F
Fortinet All Blogs
B
Blog
IT之家
IT之家
T
Tor Project blog
L
Lohrmann on Cybersecurity
Webroot Blog
Webroot Blog
博客园 - 叶小钗
Simon Willison's Weblog
Simon Willison's Weblog
Application and Cybersecurity Blog
Application and Cybersecurity Blog
量子位
Security Latest
Security Latest
TaoSecurity Blog
TaoSecurity Blog
S
Schneier on Security
C
Cisco Blogs
博客园 - 三生石上(FineUI控件)
J
Java Code Geeks
Last Week in AI
Last Week in AI
The Last Watchdog
The Last Watchdog
博客园 - 聂微东
Cisco Talos Blog
Cisco Talos Blog
Security Archives - TechRepublic
Security Archives - TechRepublic
Google DeepMind News
Google DeepMind News
SecWiki News
SecWiki News

博客园 - 火龙sky

ASP.NET Ajax发布时异步刷新失效的问题解决方法 关于Tomcat虚拟主机域名的设置--设置本地主机域名 Sql Server 中一个非常强大的日期格式化函数 针对sql 2005优化的高性能分页存储过程 大型网站架构设计 一个完美的的项目经理 CuteEditor6.0 使用 CE寻找游戏基址+偏移 VirtualAllocEx函数 了解游戏外挂 c#做外挂 step by step(更新至step3:注入) Sql-Server应用程序的高级Sql注入 教程: 汇编语言的准备知识-给初次接触汇编者4 教程: 汇编语言的准备知识-给初次接触汇编者3 教程: 汇编语言的准备知识-给初次接触汇编者2 汇编语言的准备知识--给初次接触汇编者 1 邮件简单发送 GetIP cookies 设置HtmlMeta 值
在ASP.NET中记录错误日志(使用Global.asax)
火龙sky · 2009-03-19 · via 博客园 - 火龙sky

Global.asax的Application_Error中的代码如下:

void Application_Error(object sender, EventArgs e)
    {
         // 在出现未处理的错误时运行的代码
         Exception objErr = Server.GetLastError().GetBaseException();
        string error = string.Empty;
        string errortime = string.Empty;
        string erroraddr = string.Empty;
        string errorinfo = string.Empty;
        string errorsource = string.Empty;
        string errortrace = string.Empty;

        error += "发生时间:" + System.DateTime.Now.ToString() + "<br>";
        errortime = "发生时间:" + System.DateTime.Now.ToString();

        error += "发生异常页: " + Request.Url.ToString() + "<br>";
        erroraddr = "发生异常页: " + Request.Url.ToString();

        error += "异常信息: " + objErr.Message + "<br>";
        errorinfo = "异常信息: " + objErr.Message;
        errorsource = "错误源:" + objErr.Source;
        errortrace = "堆栈信息:" + objErr.StackTrace;
        error += "--------------------------------------<br>";
        Server.ClearError();
        Application["error"] = error;
        //独占方式,因为文件只能由一个进程写入.
        System.IO.StreamWriter writer = null;
        try
        {
            lock (this)
            {
                // 写入日志
                string year = DateTime.Now.Year.ToString();
                string month = DateTime.Now.Month.ToString();
                string path = string.Empty;
                string filename = DateTime.Now.Day.ToString() + ".txt";
                path = Server.MapPath("~/Error/") + year + "/" + month;
                //如果目录不存在则创建
                if (!System.IO.Directory.Exists(path))
                {
                    System.IO.Directory.CreateDirectory(path);
                }
                System.IO.FileInfo file = new System.IO.FileInfo(path + "/" + filename);
                //if (!file.Exists)
                //    file.Create();
                //file.Open(System.IO.FileMode.Append);       
                writer = new System.IO.StreamWriter(file.FullName, true);//文件不存在就创建,true表示追加
                writer.WriteLine("用户IP:" + Request.UserHostAddress);
                //if (Session["UserName"] != null)
                //{
                //    writer.WriteLine("用户名" + System.Web.HttpContext.Current.Session["UserName"].ToString());
                //}
                writer.WriteLine(errortime);
                writer.WriteLine(erroraddr);
                writer.WriteLine(errorinfo);
                writer.WriteLine(errorsource);
                writer.WriteLine(errortrace);
                writer.WriteLine("--------------------------------------------------------------------------------------");
                //writer.Close();
            }
        }
        finally
        {
            if (writer != null)
                writer.Close();

        }
        Response.Redirect("~/Error/ErrorPage.aspx");

    }