Debug Messaging System

Db4o messaging system is a special tool, which makes db4o functionality more transparent to the user. It can be used:

In order to activate messaging before opening a database file use:

c#: Db4oFactory.Configure().MessageLevel(level)

VB: Db4oFactory.Configure().MessageLevel(level)

where level can be:

level = 0: no messages;

level > 0: normal messages;

level > 1: state messages (new object, object update, delete);

level > 2: activation messages (object activated, deactivated).

In order to set up a convenient output stream for the messages, call:

c#:

Db4oFactory.Configure().SetOut(outStream)

By default the output is sent to System.Console.Out.

VB:

Db4oFactory.Configure().SetOut(outStream)

By default the output is sent to System.Console.Out.

For more information on #setOut call see Customizing The Debug Message Output

#messageLevel(level) also can be set after a database has been opened:

c#: IObjectContainer.Ext().Configure().MessageLevel(level)

VB: IObjectContainer.Ext().Configure().MessageLevel(level)

The same applies for #setOut().

Let's use the simplest example to see all types of debug messages:

DebugExample.cs: SetCars
01public static void SetCars() 02 { 03 // Set the debug message levet to the maximum 04 Db4oFactory.Configure().MessageLevel(3); 05 // Do some db4o operations 06 File.Delete(YapFileName); 07 IObjectContainer db=Db4oFactory.OpenFile(YapFileName); 08 try 09 { 10 Car car1 = new Car("BMW"); 11 db.Set(car1); 12 Car car2 = new Car("Ferrari"); 13 db.Set(car2); 14 db.Deactivate(car1,2); 15 IQuery query = db.Query(); 16 query.Constrain(typeof(Car)); 17 IObjectSet results = query.Execute(); 18 ListResult(results); 19 } 20 finally 21 { 22 db.Close(); 23 } 24 Db4oFactory.Configure().MessageLevel(0); 25 }

DebugExample.vb: SetCars
01Public Shared Sub SetCars() 02 ' Set the debug message levet to the maximum 03 Db4oFactory.Configure().MessageLevel(3) 04 ' Do some db4o operations 05 File.Delete(YapFileName) 06 Dim db As IObjectContainer = Db4oFactory.OpenFile(YapFileName) 07 Try 08 Dim car1 As Car = New Car("BMW") 09 db.Set(car1) 10 Dim car2 As Car = New Car("Ferrari") 11 db.Set(car2) 12 db.Deactivate(car1, 2) 13 Dim query As IQuery = db.Query() 14 query.Constrain(GetType(Car)) 15 Dim results As IObjectSet = query.Execute() 16 ListResult(results) 17 Finally 18 db.Close() 19 End Try 20 Db4oFactory.Configure().MessageLevel(0) 21 End Sub

Output looks quite messy, but allows you to follow the whole process. For debugging purposes messaging system provides a timestamp and internal ID information for each object (first number in state and activate messages).