Please start any new threads on our new site at https://forums.sqlteam.com. We've got lots of great SQL Server experts to answer whatever question you can come up with.

 All Forums
 General SQL Server Forums
 Database Design and Application Architecture
 Custom application logging

Author  Topic 

KJensen
Starting Member

12 Posts

Posted - 2009-02-14 : 14:37:01
Hi

When I create an application, be it web or windows, I almost always create a log-system in SQL Server, so I can log all kind of events. This is great of tracking errors, showing history to users, etc etc.

But I am always doing it in the same way, and I wonder if others have better ideas on, how to do it.

Let me show you a simple example:







So basically for all important primary entities (like users and videos in this case), I create a column in the logging-table. I would most likely also add PageId and CategoryId, if this was not such a small project, where I did not have any use for it.

I hope it is pretty clear from the images, what I do.

Pro:
1. Very simple
2. Easy to write queries for
3. Cascading deletes can also clean up unwanted events
4. One table for logging - not many (one for logins, one for videos etc)

Con:
1. Can grow big for larger databases, mostly because of data in "Details"-field
2. Add a new table to the database, that needs logging, I have to add another column.
3. Code for logging is not reusable from solution to solution, since the table for events is different.

That is how I do it. What do you do? :)
   

- Advertisement -