New to Telerik Reporting? Download free 30-day trial

How To Disable Logging the Tracing Information from Telerik Reporting

Environment

Product Progress® Telerik® Reporting

Description

The Telerik Reporting engine uses the System.Diagnostics.Trace.WriteLine(string) method to log tracing information. Generally, this means that the information gets passed to all Trace Listeners and they should use it as required. However, the Trace.WriteLine commands cannot be filtered out and don't pass through the filter ShouldTrace. This makes it impossible to filter out the information logged by the Reporting engine.

Suggested Workarounds

You may use the approach from the Stackoverflow thread Suppress Trace Messages From Specific DLL. Here is a sample implementation for the custom Trace Listener class:

using System.Diagnostics;
using System.Reflection;

public class CustomTraceListener : TextWriterTraceListener
{
    Assembly assemblyToIgnore;

    public CustomTraceListener(Assembly assemblyToIgnoreTracesFrom, Stream stream)
        :base(stream)
    {
        this.assemblyToIgnore = assemblyToIgnoreTracesFrom;
        //this.Filter = new CustomTraceFilter(SourceLevels.All);
        this.Writer = new StreamWriter(stream);
    }

    public bool TraceIsFromAssemblyToIgnore()
    {
        var traceCallStack = new StackTrace();
        foreach (StackFrame traceStackFrame in traceCallStack.GetFrames())
        {
            MethodBase callStackMethod = traceStackFrame.GetMethod();

            bool methodIsFromAssemblyToIgnore = (callStackMethod.Module.Assembly == this.assemblyToIgnore);

            if (methodIsFromAssemblyToIgnore)
            {
                return true;
            }
        }

        // The assembly to ignore was not found in the call stack.
        return false;
    }


    public override void WriteLine(string message)
    {
        if (!this.TraceIsFromAssemblyToIgnore())
        {
            base.WriteLine(message);
        }
    }

    public override void Write(string message)
    {
        if (!this.TraceIsFromAssemblyToIgnore())
        {
            base.Write(message);
        }
    }
}

You may add a Filter in the above code if you need to filter out any other unnecessary details.

The custom Trace Listener may be used to log custom information and skip the logs from the Telerik.Reporting assembly. Here is sample code:

var reportingAssembly = Assembly.Load("Telerik.Reporting");
var listener = new CustomTraceListener(reportingAssembly, stream);
Trace.AutoFlush = true;
Trace.Listeners.Clear();
Trace.Listeners.Add(listener);
listener.WriteLine("This line should be persisted in the trace output!");

//Render the report here with the ReportProcessor and the logs from Telerik.Reporting would be skipped
In this article