Take the 2-minute tour ×

I am creating a public facing web site and one of the requirement is to write all the errors/warning in a log file.

I have try catch block everywhere and also I can catch the errors in the application error event.

Being a public facing web site, I am afraid that log file may grow exponentially (even if I create new files every day) and it may decrease the site performance. Is there any way to write the error files asynchronously, so it will not have any impact on the users?

Any sample or guidance is highly appricated.

My site is in ASP.NET Web forms and c#.


share|improve this question
See various approaches here: stackoverflow.com/questions/1181561/… –  raymond Nov 20 '12 at 4:13
add comment

1 Answer

Recommendation: Tippu I highly recommend you use ELMAH instead. It is as easy as possible to set up and will make your life so much easier (You will never write your own logging program again). It even catches unhandled exceptions!

Check out the following website on what it is and how easy it is to set up


Security: The only thing you MUST be aware of is that you must secure ELMAH otherwise your session can be hijacked. However, it is very easy to secure it. Have a look at the following website on the security issue and how to secure it.

ASP.NET Session Hijacking

5-10 Minute Setup Steps

  1. Go to Nuget, search for "ELMAH SQL" and install "ELMAH on MS SQL Server".

  2. In your "App_Readme" folder there will be a "Elmah.SQLServer.sql" file which installs a table and 3 stored procedures. Run it in the database you want this connected too. (You will have to set permissions for the Stored procedure in a live server so that it can read and write to it)

  3. Go to your web config (You will notice that ELMAH has automatically updated it for you). Find , if you don't want to have remote access leave it as is and I believe it will be secured.

If you want to allow remote access so that you can view the Error Log website anywhere you need to set it to true. You then MUST secure it. The below will secure it for Admin and deny all other users. Check out this website for more information Secure ELMAH

<location path="elmah.axd">  
            <add verb="POST,GET,HEAD" 
                type="Elmah.ErrorLogPageFactory, Elmah" />
        <allow roles="admin" />  
        <deny users="*" />
         <add name="ELMAH" 
             type="Elmah.ErrorLogPageFactory, Elmah"
             preCondition="integratedMode" />

  1. Go to your connection strings and point the "elmah-sqlserver" connection string to your specific Database.

  2. Go to your try catches and in the catch section add "ErrorSignal.FromCurrentContext().Raise(ex);"

  3. Your application will now catch Handled and Unhandled Exceptions and write the errors to a SQL Server Table. To view the errors open up a browser and go to "yourwebsite/elmah.axd"

  4. You can also set it up so the errors are sent to you. Check out the following website on how to do that: Setup ELMAH Email

Ignore the above number ordering

share|improve this answer
add comment

Your Answer


