-1

I am using VS2005 C# .NET 2.0 and SQL Server 2005.

Are there any websites that provide step by step instructions to implement event logging for my web application?

Edit:

I will like to save the log event files as a text file in the application folder.

As my web application does login, validations and checks between several SQL databases, as well as import and export of data from SQL databases. I would like to log the events above in text files.

gymcode
  • 4,431
  • 15
  • 72
  • 128
  • Are you logging them to a database? To a text file? To the event viewer? What events do you intend to log? Unhandled exceptions? All exceptions? Arbitrary data? Please give more details. – Daniel Mann Jan 27 '12 at 03:17

2 Answers2

3

I routinely use Log4Net from Apache (free).

The Apache log4net library is a tool to help the programmer output log statements to a variety of output targets. log4net is a port of the excellent Apache log4j™ framework to the Microsoft® .NET runtime. We have kept the framework similar in spirit to the original log4j while taking advantage of new features in the .NET runtime.

There is excellent documentation and it is widely used. This blog post has a nice, simple walkthrough.

A big advantage of Log4Net is that it allows you to record to multiple log destinations including text files,, the event log, SQL Server and many others.

JonnyBoats
  • 5,177
  • 1
  • 36
  • 60
  • where do I store the folder at before I add the reference to my web application – gymcode Jan 27 '12 at 03:30
  • RuiHao: What are you asking? The configuration info is stored in web.config and you reference the DLL in your project. See the documentation. I routinely install it with NuGet – JonnyBoats Jan 27 '12 at 03:32
  • is Log4Net compatible with VS2005? – gymcode Jan 27 '12 at 03:38
  • RuiHao: Yes, it is compatible with VS2005. Here is a walkthrough using VS2003 for a website: http://haacked.com/archive/2005/03/07/ConfiguringLog4NetForWebApplications.aspx – JonnyBoats Jan 27 '12 at 03:40
  • @JohnyBoats thanks. Do I require adding a reference to my project? I do not see any DLLs in the log4Net folder I downloaded – gymcode Jan 27 '12 at 03:49
  • Yes, you need to add a reference Add to the project a reference to the \bin\net\2.0\release\log4net.dll assembly in the log4net distribution. from http://sadi02.wordpress.com/2008/06/29/log4net-tutorial-in-c-net-how-can-i-show-log-in-a-file/ – JonnyBoats Jan 27 '12 at 03:52
  • @JohnnyBoats I do not see any Bin folder in the downloaded zip. Am I mistaken of what you're portraying? – gymcode Jan 27 '12 at 03:55
  • 1
    RUiHAO: Did you download the source or the binary? You want http://newverhost.com/pub//logging/log4net/binaries/log4net-1.2.11-bin-newkey.zip – JonnyBoats Jan 27 '12 at 03:58
  • I downloaded the source. Thank you – gymcode Jan 27 '12 at 04:02
2

Look into log4net for your logging needs. There's even a sample application page.

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120