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#:

configuration.MessageLevel(level)

VB:

configuration.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#:

configuration.SetOut(outStream)

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

VB:

configuration.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
01private static void SetCars() 02 { 03 // Set the debug message levet to the maximum 04 IConfiguration configuration = Db4oFactory.NewConfiguration(); 05 configuration.MessageLevel(3); 06 // Do some db4o operations 07 File.Delete(Db4oFileName); 08 IObjectContainer db = Db4oFactory.OpenFile(configuration, Db4oFileName); 09 try 10 { 11 Car car1 = new Car("BMW"); 12 db.Set(car1); 13 Car car2 = new Car("Ferrari"); 14 db.Set(car2); 15 db.Deactivate(car1,2); 16 IQuery query = db.Query(); 17 query.Constrain(typeof(Car)); 18 IObjectSet results = query.Execute(); 19 ListResult(results); 20 } 21 finally 22 { 23 db.Close(); 24 } 25 }
DebugExample.vb: SetCars
01Private Shared Sub SetCars() 02 ' Set the debug message levet to the maximum 03 Dim configuration As IConfiguration = Db4oFactory.NewConfiguration() 04 configuration.MessageLevel(3) 05 ' Do some db4o operations 06 File.Delete(Db4oFileName) 07 Dim db As IObjectContainer = Db4oFactory.OpenFile(configuration, Db4oFileName) 08 Try 09 Dim car1 As Car = New Car("BMW") 10 db.Set(car1) 11 Dim car2 As Car = New Car("Ferrari") 12 db.Set(car2) 13 db.Deactivate(car1, 2) 14 Dim query As IQuery = db.Query() 15 query.Constrain(GetType(Car)) 16 Dim results As IObjectSet = query.Execute() 17 ListResult(results) 18 Finally 19 db.Close() 20 End Try 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).