Write custom logs to a file on Orchestrator server

How to write logs to a file and customize/filter information which will be written

Bellow are some steps that can be applied to write logs to a file, choose specific logs layout and how to filter logs before writing:

1. Write logs to a file

To write robot logs into a file on Orchestrator server a new target needs to be added which will create a file on daily basis with the short date as filename:

Add a new Rule to send the logs to file:

2. Adding more information to custom logs

In case additional logs layout are needed in a custom file than the default/usual ones in the web.config (layout=“${time} ${level} ${message}”) more information can be added from the existing parameters that are written to database in the web.config file:


For example, to have additionally the machine name, the process name and the robot name, in the target definition for the File add in the layout the following parameters ${machinename} ${event-properties:item=processName} ${event-properties:item=robotName}, it will look as bellow:


3. Filtering the logs before writing them to file/Elasticsearch/other targets

There are some filters which can be applied to ignore logging specific messages/logs. Some examples :

    <logger name="*" writeTo="file">
            <when condition="length('${message}') > 100" action="Ignore" />
            <when condition="equals('${logger}','MyApps.SomeClass')" action="Ignore" />
            <when condition="(level >= LogLevel.Debug and contains('${message}','PleaseDontLogThis')) or level==LogLevel.Warn" action="Ignore" />
            <when condition="not starts-with('${message}','PleaseLogThis')" action="Ignore" />

All the filters can be found on the official Nlog Github repository

Bellow is an example of filter that will not log the messages bigger than 100 characters or logs that contain "Foo" string to the database target (if sensitive data is required to be filtered before sending)