Skip to main content
A newer version of this page is available. .

Add Custom Log Entries and Customize the Default Tracer Behavior

  • 3 minutes to read

This topic describes the API you can use to add information to XAF log files from your code. The DevExpress.Persistent.Base.Tracing class is used for this purpose.

The Tracing class does not store log strings internally. It passes all strings to the Trace.WriteLine method.

You can access the Tracing instance using the static Tracing.Tracer property and then call one of its methods.

using DevExpress.Persistent.Base;
// ...
Tracing.Tracer.LogText("Some text");

Tracing Methods

The following table list the most important methods of the Tracing class.

Method

Logged Information

Sample Result

LogText(string text)

The text passed as the method’s parameter

06.09.16 11:58:10.739 Text

LogValue(string valueName, object objectValue)

The caption and value passed as parameters, delimited by colon.

06.09.16 11:58:10.739 ValueName: ObjectValue

LogSeparator(string comment)

The text passed as the method’s parameter, and a separator under it.

06.09.16 11:58:10.739 Comment

06.09.06 11:58:10.739 ====================

LogSubSeparator(string comment)

The separator and then the text passed as the value parameter.

06.09.16 11:58:10.739 --------------

06.09.06 11:58:10.739 Comment

LogError(Exception exception)

The type and message of the specified exception, followed by the stack trace.

The error that occurred

Type: Exception type

Message: Exception message

Stack trace: ...

Custom Tracing

You can inherit the Tracing class and override its virtual methods to implement custom logging.

using DevExpress.Persistent.Base;
// ...
public class MyTracing : Tracing {
    public override void LogError(Exception exception) {
        // Implement custom logging for exceptions here.
    }
    // You can also override other virtual methods of Tracing 
}

The static Tracing.CreateCustomTracer event occurs each time a Tracing instance is created. Handle this event to replace the default Tracing instance with a custom instance.

using DevExpress.Persistent.Base;
// ...
Tracing.CreateCustomTracer += delegate(object s, CreateCustomTracerEventArgs args) {
    args.Tracer = new MyTracing();
};

You can place this code in one of the following locations:

  • in the constructor of your platform-agnostic module located in the Module.cs (Module.vb) file;
  • in the Main method of the WinForms application located in the Program.cs (Program.vb) file, before the WinApplication.Start call;
  • in the Application_Start method of the ASP.NET application located in the Global.asax.cs (Global.asax.vb) file, before the WebApplication.Start call.
See Also
How to replace XAF exception handling with Logify