Developer forum

Forum » Development » Access to logs for custom scheduled task

Access to logs for custom scheduled task

Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Hi guys,

I have a custom scheduled task that does some logging. To make it easier for users to find the log, I want to implement the logging in such a way that it works with the built-in right-click option. For that, I analyzed the source code and discovered that I need to log as /System/Log/ScheduledTasks/Task Name*.log

If I manually create a file name after the task, it shows up correctly. Yet when I open it, it doesn't show the contents of my file.

Can this be done? And if so, what's the trick? I looked at the built-in RunSqlAddIn task and it has the same issue. The right-click menu shows up but not data is ever shown. Also, it seems that the ScheduledTasks page under System shows the logs only for batch jobs, whereas the one under Integration shows it for everything that writes to the ScheduledTasks folder. Is that correct?

Let me know if you need a video, screenshots or code to support the above ;-)

Cheers,

Imar


Replies

 
Dmitriy Benyuk Dynamicweb Employee
Dmitriy Benyuk
Reply
This post has been marked as an answer

Hi Imar,
to log information from the Scheduled task AddIn you need to setup the logger:

string logFile = ScheduledTaskName.Replace(";", "--") + DateTime.Now.ToString("yyyyMMdd-HHmmssFFFFFFF") + ".log";
Logger = LogManager.Current.GetLogger("ScheduledTasks", logFile);

This logger will log to the file which is suitable for the right Log button click.

RunSqlAddIn doesn't have this code for the looger initialization, it has instead:
ILogger Logger = LogManager.Current.GetLogger("ScheduledTasks");
So that logger will log information in the file of the name format of: yyyy-mm-dd.log which is not available for the right Log button click.
So this is a bug in RunSqlAddIn logger initialization.

The right click Log content browsing behavior is the same for both pages: System->Scheduled tasks and Integration->Batch.
So if there are files in the folder: Files\System\Log\ScheduledTasks with the name of your ScheduledTaskName*.log - you will be able to see the Log button and log files content.

Regards,
Dmitrij

Votes for this answer: 1
 
Imar Spaanjaars Dynamicweb Employee
Imar Spaanjaars
Reply

Thanks Dmitrij; that did the trick!

Note for anyone else trying this, don't try this code in the task's constuctor without extra checks. Your class is instantiated when you set up a task in the backend and then the ScheduledTaskName is not available.

 

You must be logged in to post in the forum