tags:

views:

374

answers:

5

Hello!

I have an ASP.NET App that uses a .NET library. I want to enable logging to somewhere to check later the error messages.

I will log ASP.NET app and .NET library, to the same place or to different places. I don't know how to do it.

I prefer to use System.Diagnostics. from .NET Framework instead of 3rd party frameworks, but I don't know if this is the better solution.

I want to log error messages and, sometimes, custom messages.

Thank you!

A: 

ELMAH seems to be the popular framework being used in ASP.NET at the moment

Sam Saffron
A: 

I have used nlog with great success. It's old but reliable. You can configure different destinations, and different messages.

edosoft
+1  A: 

I have been using ELMAH for about a year now, and it's been a great tool. ELMAH captures any unhandled exception in your .NET app, and can log to a db, xml, or send an email to you with stack trace info.

This dotnetslackers article was a great start to get me up and running. I've used ELMAH in about 6 projects over the past year with great results. Configuration is easy. It's all done by referencing the .dll in your web project, then setting values in the web.config file. The debug info captured is very detailed. You get the full stack trace and a capture of all server variables for the request at the time.

Mark Struzinski
+2  A: 

There are plenty logging frameworks for .NET, If you want to have powerful and flexible logging in your application then you should use one of 3rd party frameworks, I prefer log4net. There are also several ways for doing this using only classes of .Net Framework.

For example you can use these approaches:

  1. The simplest way will be creation of your personal implementation of logger, for example you can just use File.AppendAllText at the place you want to log something to somewhere. If you want to use SQL database as a storage for your log entries you can use SqlCommand class filled with appropriate insert query or you can define another way of logging. But this way isn't recommended because there are many chances that others who will support your code will know usage of well known frameworks & practices and there aren't any chances that they will know your implementation, so they probably will need to read bigger amount of code.

  2. You can use EventLog class. We have used it to log critical errors (like unhandled exceptions) happened in our services and ASP.NET applications. It will allow you to have unconditional logging to system wide storage. That storage will be accessible from Microsoft Management Console (mmc) and that storage will be configurable.

  3. You can also use something like Debug.WriteLine or Trace.WriteLine for logging. In that case you will have ability to configure log listeners via editing of web.config file. You will have ability to enable or disable of logging, change ways of logging (log to file, to event log or to something else).

Dmitriy Matveev
Your answer it's great! I don't want to use 3rd party frameworks.
VansFannel