如何创建错误文件? [英] How do I create a error file?

查看:87
本文介绍了如何创建错误文件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

错误讯息: - 访问被拒绝



我尝试过:



Error message :- Access is denied

What I have tried:

try
       {
           string path = "~/Error/" + DateTime.Today.ToString("dd-MM-yy") + ".txt";
           if (!File.Exists(System.Web.HttpContext.Current.Server.MapPath("~/Error")))
           {
               File.Create(System.Web.HttpContext.Current.Server.MapPath("~/Error")).Close();
           }
           using (StreamWriter w = File.AppendText(System.Web.HttpContext.Current.Server.MapPath(path)))
           {
               w.WriteLine("\r\nLog Entry : ");
               w.WriteLine("{0}", DateTime.Now.ToString(CultureInfo.InvariantCulture));
               string err = "Error in: " + System.Web.HttpContext.Current.Request.Url.ToString() +
                             ". Error Message:" + errorMessage;
               w.WriteLine(err);
               w.WriteLine("__________________________");
               w.Flush();
               w.Close();

推荐答案

您使用Web服务器因此会同时访问您需要处理的日志文件,更好仍然使用 Apache log4net - Apache log4net:Home - Apache log4net [ ^ ]并阅读: Nikolaos Kantzelis ASP.Net博客 - 在ASP.Net应用程序中使用Log4Net [ ^ ]
Your using a web server hence there will be concurrent access to the log files which you need to handle, better still use Apache log4net – Apache log4net: Home - Apache log4net[^] and read this : Nikolaos Kantzelis ASP.Net Blog - Using Log4Net in an ASP.Net application[^]


这篇关于如何创建错误文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆