How to extract particular group of text from a log file using UI Path

Dear Community Members,

I am trying to extract a group of text from the log file. File contains multiple blocks. based on the text and need to calculate the start and end time of the log file for each block and write it into Excel file.

InPutFile

=====================================Start executing main flow=====================================
[04-26-2020 01:34:35][C1][B1][D5][XYZ][INFO]: Current loopNo: 0
[04-26-2020 01:34:35][C1][B1][D5][XYZe][INFO]: [MenuOne] Begin to Transfer Para
[04-26-2020 01:34:35][C1][B1][D5][XYZe][INFO]: [MenuTwo] Begin to Transfer Para

[04-26-2020 01:34:35][C1][B1][D5][XYZ][TRACE]: === test Start for MenuOne===
[04-26-2020 01:34:35][C1][B1][D5][XYZ][TRACE]: === test Start for MenuTwo===

[04-26-2020 02:05:00][C1][B1][D5][XYZ][INFO]: === Execute finished for MenuOne===

[04-26-2020 02:05:00][C1][B1][D5][XYZ][INFO]: === Execute finished for MenuTwo===

OutPut File should be like this: in Excel
MenuOne Start Time EndTime TotalTime
MenuTwo

Please provide your input on this. Many Many Thanks in advance.

You dont have to look into log file for time calculation.
You can have a variable at the start of your bot to store starting time and then at the end of execution again to store the time. Then calculate the difference between end time and start time.
You will get the bot execution time.

StartTime= DateTime.Now
// All your processsing logic
EndTime= DateTime.Now

ExecutionTime= EndTime.Subtract(StartTime)

Cheers

2 Likes

Dear Mihir,

Thank you soo much for the inputs.
But i need to create robot which reads external application log file. in that log file i am having start and End time for the different blocks, I need to extract it for each block then use the Subtract method.
Currently I can read the file, and convert the data into String Array I am stuck in for each loop now

Hi @Ashwini_M_C

I suppose that you have control over the external application that generates the logs. In that case you can implement the use of an StopWatch when each menu starts and print to the logs the elapsed time when each menu ends.

https://docs.microsoft.com/en-us/dotnet/api/system.diagnostics.stopwatch?redirectedfrom=MSDN&view=netcore-3.1

After that you only have to retrieve the log that contains the elapsed time instead of sort and calculate your logs.

Regards,

Andres

1 Like

Why you need to read log file,
Can you not just have start time and end time for every block while you are executing your bot for which logs are getting generated ?
That would be much faster than reading a log file and interpreting it