Why could I write log send by delphi dll and call by c# exe?

Home Forums CodeSite Why could I write log send by delphi dll and call by c# exe?

Viewing 5 reply threads
  • Author
    Posts
    • #1307
      Carl Yang
      Participant

        Hello,

        I use Delphi XE4 with codesite express, I can write log file and enable live viewer when codesite used in Delphi maked exe.

        But when I use it in DLL called by c# application, the file and viewer will not work. Until I used debug mode(set Host application as c# application and run the dll with debug mode)

        Below are my codes:

        CodeSite.Enabled := CodeSite.Installed;
          if CodeSite.Enabled then
          begin
            try
        
            Destination := TCodeSiteDestination.Create(nil);
            except
              on e:exception do
              showmessage(format('destination create fail:%s',[e.message]));
            end;
        //    showmessage('dest create ok');
            Destination.LogFile.Active := True;
            Destination.LogFile.MaxSize:=4096;
            Destination.LogFile.MaxParts:=2;
        
            Destination.LogFile.FileName :=ChangeFileExt('PMS_DLL', '.csl');//'PMS.csl';
            Destination.LogFile.FilePath := '$(MyDocs)\My CodeSite Files\Logs\';
            Destination.Viewer.Active := {false;//}True;
            CodeSite.Destination := Destination;
            CodeSiteManager.DefaultDestination:=Destination;
        
            CodeSite.Destination.Viewer.Active:=true;
            CodeSite.Clear;
        
            CodeSite.sendmsg('test msg');
          end;
        
      • #1308
        Carl Yang
        Participant

          Hi all,

          After reinstall the codesite, the problem is solved !

          BR

        • #1312
          Ray Konopka
          Keymaster

            Hi Carl,
            Glad you have it working again. I do have a couple comments regarding the code you posted. In your code, you are creating a new Destination object and you are assigning it to both the CodeSite global logger and the CodeSiteManager. By default, each logger instance uses the destination that is defined in the CodeSiteManager. This happens when the logger’s Destination property is nil. By assigning the CodeSite.Destination to a new TCodeSiteDestination instance, you are disconnecting it from the CodeSiteManager.

            Ray

          • #1313
            Carl Yang
            Participant

              Hi Ray,

              Thanks a lot for your reply !
              My purpose is to set the log file output to a dedicate file.
              Could you tell me what is the default way to update my codes ?
              And as your suggest, what kind of situation will I get when the global codesite disconnect from CodeSiteManager ?

              I had comment out the code:
              `//CodeSiteManager.DefaultDestination:=Destination;
              `
              And the log viewer and log file can show and output normally.

              Any suggest would be appreciated.

              Best regards,

              Carl

              • This reply was modified 5 years, 7 months ago by Carl Yang.
            • #1323
              Ray Konopka
              Keymaster

                Hi Carl,
                By disconnecting from the CodeSiteManager, I mean that if you change the CodeSiteManager.DefaultDestination then the logger instance will not use any of those changes.

                Setting the CodeSiteManager.DefaultDestination to the new TCodeSiteDestination instance will result in all logger instances using the same destination information.

                To log your CodeSite messages to just a log file, you simply create a TCodeSiteDestination instance and only activate the LogFile destination sub-type. An example of this is shown in the Getting Started section of the CodeSite Help.

                Ray

              • #1410
                Carl Yang
                Participant

                  Hi Ray,
                  I am very sorry to reply so lately.

                  Now I understand your suggestion and sincere thanks for correct usage on Codesite !

                  Carl

              Viewing 5 reply threads
              • You must be logged in to reply to this topic.