views:

1087

answers:

4

Hello,

What is the best way in logging actions, activities, etc done in an asp.net application. Also, which storage is best for logging these? XML? DB?

Thank you very much.

A: 

PostSharp probably. Log to a DB.

-- Edit:

This is for logging all code actions. To log all DB actions, I'd use triggers.

Noon Silk
thank you for the fast response! Can you please elaborate on the advantage between logging in the DB versus XML/other ways? Thank you very much Silky!
Martin Ongtangco
Well, XML is just a file. It will get significantly large, with all the logging, be annoying to manage, and very difficult to query. A DB is built for querying, has great backup facilities, is easy to do, and allows you to ensure a nice integrity-driven system. Of course it isn't as flexible in it's layout as XML (so you can't just write a class and all the properties naively in it) but it would be my preference *by far*. At worst you can serialise some relevant XML to a field (for a class spec, say).
Noon Silk
what if the database that keeps the logs are corrupt, what contingencies can I apply on that scenario?
Martin Ongtangco
Typical contingencies for DB corruption: Backups. You just backup your DB nightly, weekly, monthly, and then if you ever notice a failure revert to whatever is appropriate. Add more backs as is necessary for your failure rate.
Noon Silk
+1  A: 

The answer I hate most, actually applies here: "it depends". Specifically, it depends on several things:

  • Who is the logging information for? Is it intended for business users (i.e., are there actual business requirements), is the information oriented at application management, do you need insight in frequently used features, etc.
  • What is the granularity of the logged info? For instance: do you only need to know if the search function was used, do you want to know the search query or do you also need info on the actual search results?
  • How accurate & complete does the info have to be? Audit trail requirements are usually very tight, technical ones often less so.
  • Do you want to be able to roll back the actions/activities? And if so, who is going to do that (business user, support personnel)
  • What does your deployment look like? If you have a single server, logging to text files or XML is more feasible than if you have a farm/load balanced environment.

For application logging, look at well-known providers such as log4net or the Enterprise Library logging application block; both allow you to configure where you want to log to (text file, database, etc).
For logging database actions, I suggest a solution in the database. Several versions of SQL Server 2008 have built-in support for auditing, Oracle has had this for years IIANM.

tijmenvdk
hello, we are currently pushing for HIPAA accreditation.
Martin Ongtangco
A: 

If you don't need a complex auditing system, but just logging what your code is doing, I'll recommend you to use the tracing system integrated with .NET Framework and ASP.NET.

Using very simple classes in the framework, your code emit traces, and then, via configuration files you can send them to different storing systems (file, database, windows events, ...). You can even create your own store system trace provider

http://msdn.microsoft.com/en-us/library/system.diagnostics.trace.aspx

Juan Calero
A: 

I would use :log4net

because you can configure and change the output(file, mail, DB, ...) in the config file so you do not have to rebuild your code.

Pitming