Looking to output the log file into a text file

Hello @jeff.shubzda

Please refer the below post. It can help you to solve your issue.

@jeff.shubzda You can download those logs manually by using the export option in output panel

Capture

I will check and let you know how to download using UiPath code

Man, that is a seriously over-engineered solution.

I would not recommend following that posts approach its very clunky.

There is an activity already called ‘Write Line’ which will output it the text to the logs, but it also has a ‘TextWriter’ property where you can add a TextWriter, which can easily be used to output to a text file. Pretty simple.
It does mean you need to switch out your Log Messages for Write Lines however.

There are other ways of doing it which are smoother and allow you to capture the data from log events, but it involves making custom activities in .Net


seem to get an error

You need to escape back slash as \\ or add @ in front of the string.

File.AppendAllText("files\\output.txt", Output)

or

File.AppendAllText(@"files\output.txt", Output)
1 Like

once this process is completed should I not see a file n there called output.txt?

Yes, you should see an “output.txt” in the subfolder “files” where your project is located.

Can you please share is code

Just ran it and it did not write the output to the file folder,
LogWrite = (s) => {
string Output = DateTime.Now.ToString("[MM/dd/yyyy HH:mm:ss.ffff] ") + s + Environment.NewLine;
File.AppendAllText(“files\output.txt”, Output);
Console.WriteLine(Output);
};

1 Like

Jeff, as I mentioned before, the solution posted with Invoke code is absurdly over engineered. You can use a text writer with the write line activity.

how do you write the logs to that file?

Like this, its super easy. The second assign that isn’t fully visible is just setting the Autoflush property to true, do that otherwise you need to flush manually.
I would strongly recommend against the other posted solution.

So this process with take the output data and log it to a txt file once completed? Would I put this right at the beginning of the workflow?

You cannot capture that log window in either of the methods demonstrated here, the one in the link has a nasty cumbersome way to set up a custom way to log messages that go to a custom log file. I provided a simpler cleaner one, but it only logs things in the ‘Write Line’ activity. (The other custom log also doesn’t capture those extra messages).

1 Like

OK thank you for the guidance

I did not understand the solution please help me with example

There is an example in my post Aleem, I cannot help further unless you are more specific about what you do not understand?

1 Like

As the question " I would like to output this log file into a text file for review once the bot is completed and also send this to the client. " so invoke code is not good solution and bot will automatically download the log file and share it to business.

You suggested it could be possible by write line I have same scenario and please help me to overcome this problem appreciate you.

I think you misunderstand.

Neither solution, using the invoke code nor the write line activity are downloading the log file and neither are grabbing all the log messages, for example neither will capture any error messages thrown.

What they both do is provide a way to log a message that appears both in the output panel and to a custom log file. My stance is that, for such a simple function, using the invoke code method is very cumbersome when you can just use Write Line and a TextWriter Class.

To capture all of the logs there are two choices, one is to make an API call to download the logs for the current job, however you need the Job ID in order to do that which is not easy to expose. Its situationally possible to grab these logs based on other filters, but it will bot be reliable.

The other method involves hooking into the underlying logging class on the robot runner to register your own log listener.

Both of these require advanced knowledge of coding (to get the Job ID or register a listener) and making custom activities in Visual Studio.

2 Likes

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.