We have closed this ticket because another page addresses its subject:
Core - Provide an option to override the Tracing class behaviorValidation - Do not write validation exceptions to the application log file
Answers approved by DevExpress Support
Starting with v15.2.8 it will be easier for you to override the Tracing class behavior with the new CreateCustomTracer event and virtual methods of the Tracing class.
See Also:
Concepts > Debugging and Error Handling > Add Custom Log Entries and Customize the Default Tracer Behavior
Tracing - How to exclude loaded assemblies from the eXpressAppFramework.log file
How to replace XAF exception handling with Logify
Other Answers
It would be satisfying if DevExpress only made the following methods virtual:
- Tracing.LogError(Exception exception)
- Tracing.LogError(string text, params object[] args)
- Tracing.LogLoadedAssemblies()
Then, the following class could be used:
C#public class CustomTracing : Tracing
{
public static void InjectTracer()
{
FieldInfo field = typeof(Tracing).GetField("tracer", BindingFlags.Static | BindingFlags.NonPublic);
field.SetValue(null, new CustomTracing());
}
public override void LogError(Exception exception)
{
if (!(exception is ValidationException))
base.LogError(exception);
}
public override void LogError(string text, params object[] args)
{
if (!text.Contains(" Type: ValidationException"))
{
int ind = text.LastIndexOf("Loaded assemblies");
if (ind != -1)
text = text.Substring(0, ind);
base.LogError(text, args);
}
}
public override void LogLoadedAssemblies() { /* base.LogLoadedAssemblies();*/ }
}
…and initialisation of the mechanism:
C#public sealed partial class YourApplicationModule : ModuleBase
{
...
public override void Setup(XafApplication application)
{
CustomTracing.InjectTracer();
base.Setup(application);
}
}
@PHN:
>>
But on my side, only one application is running. I change log file name to another but no luck, the problem still there.
<<
This may also occur for a single application if the log file is locked. This behavior is not related to XAF, but rather to the standard .NET trace listeners mechanism, which actually prefixes a file name with a GUID.
You are free to use any custom logging solutions here. To avoid collisions, remove the default trace listeners by clearing the Trace.Listeners collection.
Thanks Dennis,
As your's comment above, if use custom tracing, the application will generate multiple log files. This is not good for finding problems in log files.
Do you have any solution for that?
@PHN:
It all looks like you did not close previously active trace listeners before injecting your custom Tracing class. Here are two ways of doing this:
C#//foreach(System.Diagnostics.TraceListener l in System.Diagnostics.Trace.Listeners) {
// l.Close();
//}
//System.Diagnostics.Trace.Listeners.Clear();
Tracing.Close(true);
CustomTracing.InjectTracer();
winApplication.Setup();
I hold my breath… ;)
Amazing how fast 4 years pass :)
I've been keeping breathless for 3 months, but I give up.