How to write logs to a file and customize/filter information which will be written
Below are some steps that can be applied to write logs to a file, choose specific logs layout, and how to filter logs before writing:
- Write logs to a file
- To write robot logs into a file on the Orchestrator server a new target needs to be added which will create a file on a daily basis with the short date as the filename:
- Add a new Rule to send the logs to file:
- 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 :
<rules> <logger name="*" writeTo="file"> <filters> <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" /> </filters> </logger> </rules>
All the filters can be found on the official Nlog Github repository
Below is an example of a filter that will not log 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)