Click here to Skip to main content
13,094,983 members (79,232 online)
Click here to Skip to main content
Add your own
alternative version


21 bookmarked
Posted 11 Jan 2004

Database Logging in .NET

, 11 Jan 2004
Rate this:
Please Sign up or sign in to vote.
Component that caches updates to a log and then persists them to a database on a timed interval.


Often times, in a hosted environment, logging to a local file or the Event Log is not an option for the developer. To solve this problem, one requires a logging solution built on a database table. However, if the volume of log updates is large and frequent, posting a command to the database for each log entry is not favorable.

To overcome this, you can use the in-memory DataTable class provided by the .NET Framework. The Logger class simply encapsulates the ability to post updates to an in-memory table and then have those updates posted in batch mode to the database on some predefined interval.


To use the Logger component, add it to the form that needs the logging functionality. Also a DataTable (or DataSet) component and a corresponding SqlDataAdapter component. Assign the table that will hold the cached version of your log writes, to the ActiveTable property of the Logger and assign the adapter to the Adapter property. The default flush time is 15 minutes, which you can change to meet your environment's needs.

Somewhere in your code (like in the application's initialization), set the Enabled property of the Logger to true. Then, for each time you want to send an entry to the log, just call the Write method.


This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


About the Author

David Hall
Chief Technology Officer
United States United States
I have been a Windows software developer since 1991. Most of what I create fills the need for some aspect of bigger projects that I consult on.

You may also be interested in...

Comments and Discussions

QuestionCode snippet? Pin
Chris Maunder21-Jan-04 2:11
adminChris Maunder21-Jan-04 2:11 
GeneralOther logging packages Pin
Giles12-Jan-04 9:06
memberGiles12-Jan-04 9:06 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.170813.1 | Last Updated 12 Jan 2004
Article Copyright 2004 by David Hall
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid