Skip to content

TjachLog_UseSeparateThreadToWrite

Juan Antonio Castillo edited this page Feb 27, 2022 · 1 revision

Class: TjachLog

Declaration: property UseSeparateThreadToWrite: Boolean read FUseSeparateThreadToWrite write SetUseSeparateThreadToWrite;

Type: Boolean

TjachLog.UseSeparateThreadToWrite property

Set the UseSeparateThreadToWrite property to True to start additional threads to write to the different destinations of the log, plus a coordinator thread.

When configured to use separate threads to write, the call to add a log entry returns almost immediately, as the only work it does is check if the entry has to be filtered and add it to a queue. This greatly speeds up the calling thread in exchange for a delay to see the entry appears in the current log destination and the risk to terminate the application before all generated messages are written to the log.

Is up to you to weigh what is better for your solution. There are some cases when it's better a delay on the current operation and have the log always updated and there are some cases when you have to maintain the best performance, even if it means a delay to see the entries appear and the mentioned risk about not getting all of them.

Set the UseSeparateThreadToWrite property to False (it's default value) and the messages will be written to the destination in the context of the calling thread (unless the IsCached property is set to true.

This means the Log method call will not return until the entry is actually written to all available destinations.

For more information and examples read writing to destinations using multiple threads.