Bad category in TraceMethod

Home Forums CodeSite Bad category in TraceMethod

Viewing 1 reply thread
  • Author
    Posts
    • #2776
      mitzi
      Participant

        I found strange thing. When TraceMethod is called, it logs Category from previous log record. I don’t know if it is intent or bug, but it is very confusing. See attached picture. Category in selected line has nothing to do with logged record.

      • #2779
        Ray Konopka
        Keymaster

          Hi,

          I suspect that you are using the same logger instance when calling the TraceMethod method as well as the other Send() calls within the method. The TraceMethod call will result in the same logger to be used when the method exits to send the ExitMethod message. Therefore, if the category of the logger changes inside the method, then that category will be used when sending the ExitMethod message. You would get the same behavior if you called EnterMethod() instead of TraceMethod at the beginning of the method, and ExitMethod() at the end.

          However, if you use a separate logger instance, then the categories are maintained. For example,

          procedure TForm30.FormCreate(Sender: TObject);
          begin
            CodeSite.Category := 'CodeSite';
            csTracer := TCodeSiteLogger.Create( Self );
            csTracer.Category := 'Tracer';
          end;
          
          procedure TForm30.Button1Click(Sender: TObject);
          begin
            csTracer.TraceMethod( 'Button1Click' );
            CodeSite.Send( 'Height', Height );
            CodeSite.Send( 'Main Form', Self );
          end;

          The csTracer is defined as a private field in the form declaration. When you click the button, the EnterMethod and ExitMessage messages in the Viewer will be associated with the “Tracer” category, while the Height and Main Form messages will be associated with “CodeSite”.

          Ray

      Viewing 1 reply thread
      • You must be logged in to reply to this topic.