top of page

UiPath – Simple Local Logging

Like we know logging on UiPath handled by its Orchestrator. Of course, not all people prefer this method, some people prefer using simple and standard method which is using local file such as text or excel file.

In this article we will try to make our own simple local logging mechanisms using excel file as its storage. Which can be used or called by another workflow.

  • Open UiPath Studio, create new Process. Type in Name, Location, Description, etc. Click Create.

  • After the main page appear, add new workflow file by clicking [New > Sequence] on the main menu on the top.

Type in “Write Log” as the Name, click Create.

In this “Write Log” workflow the logging process will be done. Which will be called or used by Main workflow.

  • First create 2 new variables, by opening Variables tab on the middle bottom part of UiPath Studio: - dtLog, DataTable data type. Will be used to store the log information before it saved into the excel file. - logFilename, String data type. Contains information of excel filename and location to keep the log informations. The log file mechanism is 1 file per day, with naming format: “Log_[Year][Month][Day].xlsx”

  • Create 4 “In” direction arguments as parameters that will be sent from the caller workflow: - in_level, String argument type. Contains information of log level such as debug, error, information, etc. - in_workflowFilename, String argument type. Contains information of caller workflow filename, to help knowing where this written log came from. - in_description, String argument type. Contains message that will be stored in the log, such as error message, exception message, debug message, etc. - in_logFolder, String argument type. Contains folder location of where this log file will be stored.

  • Let us add our first activity into the workflow, [Build Data Table]. Set the dtLog variable as the Output DataTable.

  • Click the [DataTable…] button to define the columns will be used. Remove all the default columns then add following columns: - Time, - Level, - Workflow Name, - Message All in String data type.

  • Add new activity, [Add Data Row]. Set dtLog variable as Input DataTable, and following value as Input ArrayRow value:

{ Now.ToString("dd/MM/yyyy HH:mm:ss"), in_level, in_workflowFilename, in_description }
  • Add new activity, [Assign]. To define excel log file name. Since we are using “Log_[Year][Month][Day].xlsx” as the naming format, set following value as the value for the logFilename variable:

string.Concat(in_logFolder, "\Log_", Now.ToString("yyyyMMdd"), ".xlsx")
  • Add new activity, [If]. To check whether today excel log file already exists or not. Use following as the condition:

  • If today excel file already exists, then add new activity, [Append Range] from: System > File > Workbook > Append Range. Set following as the property values: Workbook path = logFilename SheetName = “Log” DataTable = dtLog

  • If today excel file does not exists, then add new activity, [Write Range] from: System > File > Workbook > Write Range. Set following as the property values: Workbook path = logFilename SheetName = “Log” DataTable = dtLog AddHeaders = checked

Until here the process to save/write log workflow already complete. Next, back to the Main workflow.

  • In the Main workflow add new activity, [Invoke Workflow File]. Then type "Write Log.xaml" as the WorkflowFileName value. We call this workflow for logging process, which in here is to inform that the process is already started.

Or we could do another way by drag n drop “Write Log.xaml” file from Project tab to the workflow.

  • Click [Import Arguments] button to type values that will be stored in the log file, click OK.

  • Change this activity DisplayName to “Write log – Start Workflow” to make it more informative and differ from another [Invoke Workflow File] activities.

  • Add new activity, [Delay]. Put 00:00:05 (5 seconds) as Duration value. This [Delay] activity is used to simulate that after the previous activity (write log) is executed, the robot running another process that took 5 seconds duration.

  • Add new activity [Invoke Workflow File] again, same as before. But this time we use to inform that the process is already completed. Or we could do Copy-Paste from previous [Invoke Workflow File] activity.

Do not forget to change the DisplayName to “Write Log – End Workflow”.

  • Click [Import Arguments] button again to type values that will be stored into the log file. All values are the same as before except for “in_description”, type “Process finished” as the value.

Workflow creation is complete. Next, let us run this workflow and see the result by clicking [Debug File] button on the main menu or by pressing F5 from the keyboard.

The result should be like this:

Besides this method, make new workflow file “Write Log” and invoke it from Main or another workflow, there is another method to make this logging process. We could make this “Write Log” as a Library (reusable components) in separate UiPath project, then we add the output package of this project into our main project through Manage Packages. After installed, this “Write Log” will be recognized as regular activity. We could add or drag n drop it into our workflow, set the property value and so on.

For Library (reusable components) project will be discussed in another article. Stay Tune!

305 views0 comments


bottom of page