Ticket T500609
Visible to All Users
Duplicate

We have closed this ticket because another page addresses its subject:

Core - Provide an option to override the Tracing class behavior

Tracing - How to exclude loaded assemblies from the eXpressAppFramework.log file

created 8 years ago

How can I implement a customized Tracer to not out assemblies to the log file?

Answers approved by DevExpress Support

created 8 years ago (modified a year ago)

Hello Scott,

The list of loaded assemblies has helped us many times track down customers' problems, especially when several versions of the same assembly were loaded. So, it is generally required, at least for diagnostic.

If you do not like it, consider the following solution instructions to remove it completely:
1.  Create and register a custom Tracing class as per the "Custom Tracing" section of the Concepts > Debugging and Error Handling > Add Custom Log Entries and Customize the Default Tracer Behavior  article.

Blazor (YourSolutionName.Blazor.Server\Startup.cs)

C#
namespace dxT735510.Blazor.Server; public class Startup { public void ConfigureServices(IServiceCollection services) { Tracing.CreateCustomTracer += delegate (object s, CreateCustomTracerEventArgs args) { args.Tracer = new MyTracing(); }; Tracing.Initialize(); // It is important to register a custom tracing class before all other code

WinForms (YourSolutionName.Win/Program.cs)

C#
namespace YourSolutionName.Win { static class Program { [STAThread] static void Main(string[] arguments) { Tracing.CreateCustomTracer += delegate (object s, CreateCustomTracerEventArgs args) { args.Tracer = new MyTracing(); }; Tracing.Initialize(); // It is important to register a custom tracing class before this call!!! DXApplication1WindowsFormsApplication winApplication = new DXApplication1WindowsFormsApplication();

ASP.NET WebForms (YourSolutionName.Web/Global.asax.cs)

C#
namespace YourSolutionName.Web { public class Global : System.Web.HttpApplication { protected void Session_Start(Object sender, EventArgs e) { Tracing.CreateCustomTracer += delegate (object s, CreateCustomTracerEventArgs args) { args.Tracer = new MyTracing(); }; Tracing.Initialize(); // It is important to register a custom tracing class before this call!!! WebApplication.SetInstance(Session, new DXApplication1AspNetApplication());

2.  Override the LogLoadedAssemblies and LogError methods as shown below:

C#
using DevExpress.Persistent.Base; //... public class MyTracing : Tracing { //Prevent logging loaded assemblies at the application startup. public override void LogLoadedAssemblies() { //base.LogLoadedAssemblies(); } //Prevent logging loaded assemblies that are logged when an exception is thrown. public override void LogError(Exception exception) { string report = FormatExceptionReport(exception); report = report.Replace(report.Substring(report.IndexOf(Tracing.SubSectionDelim)), Tracing.SectionDelim); LogError(report); } public override void LogError(string text, params object[] args) { int startIndex = text.IndexOf(Tracing.SubSectionDelim); if(startIndex > 0) { text = text.Replace(text.Substring(startIndex), Tracing.SectionDelim); } base.LogError(text, args); } }

See Also:
How to replace XAF exception handling with Logify

    Show previous comments (4)
    YV YV
    YouSoft Vietnam 7 years ago

      Actually, I implemented quite the same. However it still log the loaded assemble. Please take a look on my code.
      And I call  SubscribeEvents before XafApplication.Start().

      C#
      public class TracingEx : Tracing { //Prevent logging loaded assemblies that are logged when an exception is thrown. public override void LogError(Exception exception) { Debug.WriteLine("/////////////////////////////////Before writing alog/////////////////////////////////"); string report = FormatExceptionReport(exception); report = report.Replace(report.Substring(report.IndexOf(Tracing.SubSectionDelim)), Tracing.SectionDelim); Debug.WriteLine($"{report}"); LogError(report); } public override void LogVerboseError(Exception exception) { LogError(exception); } //Prevent logging loaded assemblies at the application startup. public override void LogLoadedAssemblies() { Debug.WriteLine("/////////////////////////////////Do nothing/////////////////////////////////"); //base.LogLoadedAssemblies(); } public static void SubscribeEvents() { Debug.WriteLine("===================init init ==========================="); CreateCustomTracer += delegate (object sender, CreateCustomTracerEventArgs e) { e.Tracer = new TracingEx(); }; } }

        Hi Jason,

        Please look at the DevExpress source file:
        "C:\Program Files (x86)\DevExpress 18.1\Components\Sources\DevExpress.ExpressApp\DevExpress.ExpressApp\DevExpress.Persistent.Base\Tracing.cs"

        The culprit method formatting the loaded assemblies is FormatLoadedAssemblies. It is called exactly 2 times. Once in the LogLoadedAssemblies that you can override to do nothing. This will remove the loaded assemblies from the beginning of the log. The second time it is called, is from a method you call in your code: FormatExceptionReport.

        C#
        public static string FormatExceptionReportDefault(Exception exception) { List<string> report = new List<string>(); report.Add(SectionDelim); report.Add("The error occurred:"); report.Add(""); FormatExceptionReport(exception, report, ""); FormatLoadedAssemblies(report); // <------------------------------------------- report.Add(SectionDelim); report.Add(string.Empty); return string.Join("\r\n", report.ToArray()); } public string FormatExceptionReport(Exception exception) { return FormatExceptionReportDefault(exception); }

        Perhaps DevExpress could make FormatExceptionReport virtual since it is called at so many places. In the mean time, creating your own MyFormatExceptionReport(Exception exception) should solve this.

        I'm sorry I didn't see that second occurrence, I do not use the default error formatter.

        HTH

        Alex

        Andrey K (DevExpress Support) 7 years ago

          Hello,

          Thank you for your feedback. We will consider this code when planning future updates. For now, to get rid of entries about loaded assemblies, use the code Dennis suggested in the answer. The LogError method in it removes entries about loaded assemblies.

          Thanks,
          Andrey

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.