How to write logs at external script

Discussion in 'Call Flow Designer' started by Larikov Sergey, Mar 5, 2018.

Thread Status:
Not open for further replies.
  1. Larikov Sergey

    Joined:
    Mar 2, 2018
    Messages:
    2
    Likes Received:
    0
    Hello! I started to build automatic dialer with CFD and there was a question about logging at external script.

    I copied the code from the topic
    https://www.3cx.com/community/threads/find-amount-of-available-call-queue-agents.49551/
    http://myprintscreen.com/s/rgn2/2d13dd2d69

    And everything works as it should and thanks to the author for code :)
    However it is necessary to do additional logging at this code but I can not to do this.


    In file "3CXObjectModel.2.0.0.0_v15.chm" I found that PhoneSystem contains the necessary interface http://myprintscreen.com/s/rgn5/20dbe7cef8
    I added a line of code to the FreeAgentsCount.CountFreeAgents

    PhoneSystem.Logger.Error("THISasdjasjlksdk182793 unique string for test");

    I build the project, upload it, restart queue and it works at it should.
    But here in any messages at log files (i try to find at '3CXQueueManager.log' and other 3CX log files...)

    Please tell me how to log messages in external script and where are they stored?
    Thank you for your help and time.
     
    #1 Larikov Sergey, Mar 5, 2018
    Last edited: Mar 5, 2018
  2. edossantos

    edossantos Support Team
    Staff Member 3CX Support

    Joined:
    Jun 27, 2007
    Messages:
    1,361
    Likes Received:
    109
    Hello @Larikov Sergey,

    The logger used by CFD apps, which logs to the 3CXQueueManager.log file, is not exposed to the scripts, so you can't use it to log from your script. You can use the Logger component to do it, but you can't call a Logger component from your code...

    I'm not sure where the Logger property from the PhoneSystem class writes the log, but anyway it should be pretty simple to create a simple method to log to your own text file, something like:
    Code:
    public static void Log(string fileName, string text)
    {
      File.AppendAllText(fileName, text + Environment.NewLine);
    }
    Kind regards.
     
    Stop hovering to collapse... Click to collapse... Hover to expand... Click to expand...
  3. Larikov Sergey

    Joined:
    Mar 2, 2018
    Messages:
    2
    Likes Received:
    0
    @edossantos thanks for the solution. This is the easiest way.

    Here is the final solution for 'Log' function

    Code:
    public static void Log(string text)
            {
                string fileName = "/var/lib/3cxpbx/Instance1/Data/Logs/FreeAgentsCount.log";
    
                string logMessage = String.Format("[{0}]: {1}", DateTime.Now.ToString(), text + Environment.NewLine);
    
                File.AppendAllText(fileName, logMessage);
            } 
     
Thread Status:
Not open for further replies.