Hi,
The user asp.net process is running under har full permission in the
folder where the code lives.
Does the log folder/file resides in this folder?
Actually Server.ClearError(); was irrelavant to your problem here, it was
just a suggestion as it prevents the error from continuing to the
Application_Error event handler.
Could you send the code for AddLogEntry(Request, ex)?
This is how I do it:
<%@ Import Namespace = "System.IO" %>
<%@ Import Namespace = "System.Diagnostics" %>
void Application_Error(object sender, EventArgs e)
{
//Only redirect to error page if in Release mode.
#if DEBUG
{
//Show error details
}
#else
{
try
{
LogError(Server.GetLastError().GetBaseException()) ;
Server.ClearError();
}
catch
{
//Do something.....
}
//Redirect to error.aspx page
Response.Redirect("error.aspx");
}
#endif
}
private void LogError(Exception objError)
{
try
{
string sLogFilePathAndName = String.Format(@"{0}{1} {2}.log",
Server.MapPath("~/Logs/"), DateTime.Now.ToLongDateString(),
DateTime.Now.DayOfWeek);
using (StreamWriter sw = File.AppendText(sLogFilePathAndName))
{
sw.WriteLine(Environment.NewLine);
sw.WriteLine(String.Format("Error Caught in Application on
{0} {1} @ {2}", DateTime.Now.DayOfWeek, DateTime.Now.ToLongDateString(),
DateTime.Now.ToLongTimeString()));
sw.WriteLine(String.Format("IP Address: {0}",
Request.ServerVariables["REMOTE_ADDR"].ToString()));
sw.WriteLine(String.Format("Platform: {0}",
Request.Browser.Platform));
sw.WriteLine(String.Format("Browser: {0}",
Request.Browser.Type));
sw.WriteLine(String.Format("Error in: {0}",
Request.Url.ToString()));
sw.WriteLine(String.Format("Error Message: {0}",
objError.Message.ToString()));
sw.WriteLine("Stack Trace:");
sw.WriteLine(objError.StackTrace.ToString());
sw.WriteLine(Environment.NewLine);
sw.WriteLine("-------------------------------------------------------------------------------------");
sw.Close();
}
}
catch
{
//Do something.....
}
}
You may also want to look at:
http://support.microsoft.com/default...b;en-us;306355
Hope it helps
Med
"Smith" <Sm***@pricateemail.comwrote in message
news:e5**************@TK2MSFTNGP05.phx.gbl...
>
"Med" <no****@nowhere.nowherewrote in message
news:%2****************@TK2MSFTNGP02.phx.gbl...
>Hi,
Does asp.net process has write /modify permission on the folder/file that
you are attemting to write? I would also use:
Server.ClearError(); before redirecting.
The user asp.net process is running under har full permission in the
folder where the code lives.Also note that the modified date of the error
file actually change according to the time error occured. It this was
permission problem, would it be allowed to actually open the file?
How does ServerClear() helps here?
Thanks
S