Logging for ASP.NET - Best Practices

15,868

Solution 1

If you are only looking for logging of exceptions that make it back to the user, try ELMAH:

http://code.google.com/p/elmah/

On the other hand, if you are looking to track the activity in you app, you can certainly try log4net. I prefer nLog myself, you can find it here:

http://www.nlog-project.org/

Both of these are open source.

Solution 2

You should really look at log4net. See this question It might seem like more than you need right now, but once you have it as part of your architecture, it will be available and ready whenever you need it.

Solution 3

you can try System.Diagnosis.TraceSource, which built in .NET 2.0

Logging best practices

Solution 4

Another vote here for log4net. I have a complex remoting application hosted in an Windows service, and it has been extremely useful.

log4net is very powerful and also easily configurable. You can do minimum logging all the time, then switch on more verbose logging in multiple increments by changing a configuration setting.

Solution 5

I'd recommend the Microsoft Enterprise Library which contains the Logging Application block. I've been using it for some time and it works well.

http://www.codeplex.com/entlib/Release/ProjectReleases.aspx?ReleaseId=4474

I use it in WebApps to write out to the Virtual Directory. It's fairly granular and you can easily customise it for your own application

This http://www.codeproject.com/KB/architecture/GetLoggingWithEntLib.aspx is a good article about using it

Share:
15,868
C. Ross
Author by

C. Ross

I'm a professional software engineer, with a background in Android, C#, and Java systems throughout the stack, and experience in several industries.

Updated on June 04, 2022

Comments

  • C. Ross
    C. Ross almost 2 years

    What is the best way to write minimal error logs in an ASP.NET 2.0 web page or web service? For my purposes it'd be best if this was vanilla, and the implementation would work through IIS's virtual directories. I'm currently using the standard TextWriterTraceListener, but it doesn't seem to write to the virtual directory.

    FYI - the TextWriterTraceListener's configuration follows:

    <system.diagnostics>
        <trace autoflush="true">
          <listeners>
            <add name="myListener" type="System.Diagnostics.TextWriterTraceListener" initializeData=".\VirtualDirectory\SomeLog.log" />
          </listeners>
        </trace>
      </system.diagnostics>
    

    I appreciate your help!