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.
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 |
|
LogValue(string valueName, object objectValue) | The caption and value passed as parameters, delimited by colon. |
|
LogSeparator(string comment) | The text passed as the method’s parameter, and a separator under it. |
|
LogSubSeparator(string comment) | The separator and then the text passed as the value parameter. |
|
LogError(Exception exception) | The type and message of the specified exception, followed by the 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.