Search code examples
design-patternsfactoryevent-log

Design pattern for writing to various eventlogs


We have a system which is composed of few applications. Each application at certain points need to generate an event to one of event logs. (Event logs is a table in a database having attributes that define event log number, event type and so on.) All event logs have certain common attributes, but every log has some specific attributes (so there'll be a sparse table). Every event log supports its own set of events. These events dictate which additional fields are to be written. Application knows event log number and event type it must generate at certain points of execution.

I'm looking for design patterns which will help us achieve this. We need to write a library usable by applications, so each developer will have an easy to use classes for the purpose of inserting event data. Speaking at the "code level", I want to reduce client code to call to a single method with a signature specific to event it needs to generate. So far I came up with a Factory (most likely it'll be also a Singleton) which will have 10 methods (10 event logs). Each method generates an appropriate class (say, EventLog1Entry) which will provide method for writing data to db.
What to do further I do not know. Any suggestions?

P.S. This is my first attempt to use some design pattern, so forgive me if I use professional terms too freely.


Solution

  • You may want to check out log4net - it already supports everything you want and in addition is highly optimized and extensively tested.

    Even if you don't want to just use it "as is", it may give you some pointers on which design has proven itself over the years.