Logging part I

Welcome to logging part I

Recently I had a nasty error in production on an asp.net web site application that gave me an error only on one page :)

So because this was on production and I was in a very big harry I had to do something fast. The only thing I could think of was to add on the fly (because it is a web site project each page was compiled at access time - yes the project did not have a global error handler - we'll get there) I added on the page this:

void Page_Error(object sender, EventArgs e) { System.IO.File.WriteAllText(@"C:\Dev\ErrorLog.txt", Server.GetLastError().ToString()); }

On the next publish (web site) just put the Global.asax file in the project either add the file with File / Add New and search global application in search and chose Global.asax file.

In the appropriate Application_Error section say:
public static void InsertText( string path, string newText )
    if (File.Exists(path))
        string oldText = File.ReadAllText(path);
        using (var sw = new StreamWriter(path, false))
    else File.WriteAllText(path,newText);
On my next part of logging I will talk about logging with nlog - divers scenarios.


Postări populare de pe acest blog

DevExpress Theme Changer ...


5Inch HDMI LCD for RPI 800x480