用于写入各种事件日志的设计模式
我们有一个由几个应用程序组成的系统。每个应用程序在某些时刻都需要向事件日志之一生成事件。 (事件日志是数据库中的一个表,具有定义事件日志编号、事件类型等属性。)所有事件日志都有某些共同属性,但每个日志都有一些特定属性(因此将有一个稀疏表)。每个事件日志都支持自己的事件集。这些事件指示要写入哪些附加字段。应用程序知道它在某些执行点必须生成的事件日志编号和事件类型。
我正在寻找能够帮助我们实现这一目标的设计模式。我们需要编写一个可供应用程序使用的库,因此每个开发人员都将有一个易于使用的类来插入事件数据。在“代码级别”上,我希望减少客户端代码以调用具有特定于它需要生成的事件的签名的单个方法。 到目前为止,我想出了一个工厂(很可能它也是一个单例),它将有 10 个方法(10 个事件日志)。每个方法都会生成一个适当的类(例如,EventLog1Entry),它将提供将数据写入数据库的方法。
进一步做什么我不知道。 有什么建议吗?
PS 这是我第一次尝试使用一些设计模式,所以如果我使用专业术语过于随意,请原谅我。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可能想查看 log4net - 它已经支持您想要的所有内容,此外还经过高度优化和广泛已测试。
即使您不想“按原样”使用它,它也可能会给您一些指示,让您了解哪些设计多年来已经证明了自己。
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.