Have one log file per process per day by modifying nlog.config file

Hi !
I want to have one log file per day per process.
I would only like to modify in the nlog.config file.

Thus, I am trying to modify the filename of the logs file, but I didn’t succeed…

Steps I tried:
I went to C:\Program Files\UiPath\Studio and modified the file nlog.config
I tried to add several attributes at type File in filename tag.

Like originally the file was:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_Execution.log" layout="${time} ${level} ${message}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" />
  </targets>
</nlog>

and I modified it as:

<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <variable name="WorkflowLoggingDirectory" value="${specialfolder:folder=LocalApplicationData}/UiPath/Logs" />
  <rules>
    <logger name="WorkflowLogging" writeTo="WorkflowLogFiles" final="true" />
  </rules>
  <targets>
    <target type="File" name="WorkflowLogFiles" fileName="${WorkflowLoggingDirectory}/${shortdate}_${processname:fullName=true}_Execution.log" layout="${time} ${level} ${message}" keepFileOpen="true" openFileCacheTimeout="5" concurrentWrites="true" encoding="utf-8" writeBom="true" />
  </targets>
</nlog>

I tried to understand the documentation of https://nlog-project.org/config/?tab=layouts but couldn’t use it properly…

Does someone know how to do it ?

Thanks ! :grin:

Hey @Hiba_B

So you mean no matter how many times you run a process you want only one log file ?

Thanks
#nK

I mean for example if I have 3 processes and they run monday and tuesday, then
I want to have 6 log files that contain logs of monday process 1, monday process 2, monday process 3, tuesday process 1, tuesday process 2, tuesday process 3

Hey @Hiba_B

So that means for every process only one log file per day ?

Thanks
#nK

Yes that’s it

This needs some bit of research let’s see if I get something.

Hello @Hiba_B

Does that mean your process will execute multiple times per daya and you need to retain a single log file per process?

For example Process 1 can execute multiple time a day and you need to retain one log file for that process for the day?

Hi @Rahul_Unnikrishnan : Yes

You can try the following approach:

1/ set environment variable (e.g. ProcessName) to your process name e.g. using folloving VB code
system.Environment.SetEnvironmentVariable("ProcessName", "MyProcess")

2/ Use the environment variable in the log file name in NLog.config
fileName="${WorkflowLoggingDirectory}/${environment:ProcessName}_${shortdate}_Execution.log"

NOTE: Only after setting the environment variable the log file name will have the expected format. Therefore setting the enviroment variable should be the very first activity in the process.