Any examples of using Logging in a 3-tiered architecture setting?

Topics: Building and extending application blocks, General discussion, Logging Application Block
Nov 2, 2007 at 2:59 PM
Hi all,

I am brand new to the Enterprise Library 3.1. I am building a 3-tier ASP.Net web application and I want to incorporate logging. I will have my presentation tier (aspx web page and code behind), my buisness logic layer (Class files such as Customers.vb) and then my data access and logging tier ( Enterprise Library 3.1). Or this is how I would have done this in the past. I have never done logging before so is this the correct structure? I really need help on how to capture logging info and then writing it to a SQL table. I also need help on how to design my new application so that I can easily use this logging layer.

I want to log certain events like when a user logins in and logs out. I also will have some other custom events that I'd like to log. I also want to log these events to a SQL Server 2005 database and insert rows into a table that I create and define.

I cannot find any examples of doing this while searching the web. I am sure what I am trying to do is fairly typical, right? Can anyone help quide me or at least post some links of examples. At this point, I am totally clueless on how to use logging and how to architect my new application.

Nov 2, 2007 at 6:15 PM

The first place I would starting looking is in the Quick Starts. The Logging Quick Start solution should give you a basic understating of what is needed. If you want to log to a database the logging application block contains a Database Trace Listener. When you write to the Logger, the logging application block uses the category specified to route that log entry to a Trace Listener. I would start with using a flat file first, then move on to the Database Trace Listener. If you search for "Database Trace Listener" you will find some common question and answers.

Good luck,

Nov 5, 2007 at 4:23 PM

I appreciate your post. But I still am confused. I created my own SQL table called LogSession. I have my own columns that I defined. All the examples I see are as follows:

Dim logEntry As LogEntry = New LogEntry()
logEntry.EventId = 100
logEntry.Priority = 2
logEntry.Message = "Informational message"
logEntry.Categories.Add("UI Events")

But my SQL table has columns such as IPAddress and MachineName. How do I incorporate my own columns and then populate them? Also, I am confused by the term "Category". Do I really need this? Again, all I want to do is write to a table that I designed.

Nov 8, 2007 at 2:16 PM
Edited Nov 8, 2007 at 2:17 PM
The LAB is based on categorization since the release for 2.0.

Using categorization you can create a hierarchy of categories where each category can react differently. If you don't need this...then just use one category for everything and don't display it in your SQL table.
Nov 8, 2007 at 2:23 PM
Ok, thanks for clarificatoin on Categories. But what about logging to a custome SQL table? I have had no luck with this. I can log to the Log table that gets created when running the SQL script that comes with EL 3.1. But I cannot figure out how to write to my own SQL table.

Nov 26, 2007 at 2:25 PM
I am having the same problem. I am using a formatteddataasetracelistener to write event information to a sql server table. I have connection information to the sql server database in the config file. The code compiles okay, but nothing gets written to the table and I get no run-time errors. If I call the stored procedure "WriteLog" directly from code, I get a log entry in the table. But, if I use the trace listener as below, I get nothing. Please help, thank you.

Data.Database db = Data.DatabaseFactory.CreateDatabase();
errorsTraceSource.Listeners.Add(new FormattedDatabaseTraceListener(db, "WriteLog", "AddCategory", formatter));