The following change are commited in the source code.
- Support for multiple event writers.
- Event writer has it's own event level to trigger.
- Event writers are registered at the manager on the write method. No need to implement IEventWriter interface.
- Set-up of of a BlackBox manager is more transparent eg. removed Initialize method since it could be easely forgotten.
- Writing of events in the threaded BlackBox manager is triggered with an AutoResetEvent and not a constant while with a Thread.Sleep(n) (improves performance).
- Add console writer.
- Add mock writer to simplify testing.
- Add thread name in the event message.
- T-SQL writer adds a application column to filter multiple applications writing to the database.
- Removed some EventTypes (eg. All could be used in a write and is confusing).
- Add a static class System.Log which holds a BlackBoxManager instance so it's easily available in your software.
- Log class has simplified logging methods (eg. Log.Debug, Log.Trace, Log.Error, Log.Critical and Log.Warning).
- Tests for all classes with logic.
- Full XML documentation.
- Lots of small changes.
BlackBox is a modular logging framework. It’s based on a logging codebase used in my previous projects. At one point I decided to use this codebase and create a logging framework so I don’t need to copy-paste the code in my new projects.
At this time BlackBox is used in two projects that are in production state.
How it works.
BlackBox consists of two main parts, the
manager and the
event writer. The events are pushed to the manager who manages the event writers. The event writer handles the way how the events are persist.
Sample code to write a new event:
log.Write(EventTypes.Warning, "File not found.");
I love convention over configuration since it is very clear in code how it’s configured. BlackBox can be completely be configured in code (but also through the config). Unlike most loggers I don’t work with a static
instance/singleton since the developer should choose if it needs to be static.
Sample code to set up the logger:
// Creates a event writer.
EventFileWriter writer = new EventFileWriter();
// Set up the log manager.
BlackBoxManager log = new BlackBoxManager();
// Register the writer to the log manager.
- Single thread manager.
- Multi thread manager.
- File system writer.
- T-SQL writer.
- Windows Event System writer.
- Console writer.
- Mock-up writer.
- Extensible (e.g. extend file writer to define new file lay-out).
- Fallback event writer when the primary writer don't work (e.g. database down).
To do list.
- Create a NuGet package.
- Add a PostgreSQL writer.
- Add a MySQL writer.
- Add a XML formatted file writer.
- Create viewers for certain writers.
The test project depends on xUnit v1.9.1 installed from NuGet.
The icon used for Black Box is from the 2001: Space Odyssey icon pack made by Mischa McLachlan (Zyotism). Source: http://www.iconarchive.com/show/2001-space-odyssey-icons-by-zyotism.html.