Because I had a hard time tracking these down online, I thought it would be prudent to blog some simple steps which may be followed to implement database logging using enterprise library.
1. To create a logging database, run the LoggingDatabase.sql script which by default is installed at C:\EntLib4Src\Blocks\Logging\Src\DatabaseTraceListener\Scripts. This script will create a table with logging capabilities.
2. Create a project
3. Add references to:
Microsoft.Practices.EnterpriseLibrary.Common.dll
Microsoft.Practices.EnterpriseLibrary.Logging.Database.dll
Microsoft.Practices.EnterpriseLibrary.Logging.dll
4. Add a config file to the project
5. Update the config file using VS or EE config manager including:
Data Access connection string to db
Database trace listener
Reference to database trace listener in general log category
Reference to Data access connection in database trace listener
6. Within the entry point of the project project (using button click below) add:
Imports Microsoft.Practices.EnterpriseLibrary.Logging
Public Class Form1
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Dim log As New LogEntry
log.EventId = 1
log.AppDomainName = Me.Name
log.Title = "messageType"
log.Categories.Add("General")
log.Priority = 1
log.Message = "Test Message"
Logger.Write(log)
End Sub
End Class
Following these steps will result in a log to the database.
Filters may be applied to categorize logged messages.
No comments:
Post a Comment