I would suggest having a separate sub-flow that logs whatever you want into a pre-defined text file. And then call that sub-flow when you want to log anything.
I would suggest watching this video: https://www.youtube.com/watch?v=QjrxLPg_TdI It covers best practices for PAD developers. While I personally do not agree with some of what the author suggests there, he does cover a rather okay'ish way of logging.
A very simplified Log sub-flow could look like this:

Here's a snippet that you can copy and paste into PAD:
DateTime.GetCurrentDateTime.Local DateTimeFormat: DateTime.DateTimeFormat.DateAndTime CurrentDateTime=> CurrentDateTime
Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyy-MM-dd HH:mm:ss''' Result=> TimeStamp
Text.ConvertDateTimeToText.FromCustomDateTime DateTime: CurrentDateTime CustomFormat: $'''yyyy-MM-dd''' Result=> DateStamp
File.WriteText File: $'''C:\\RPA\\%ProjectName%\\Logs\\%ModuleName% %DateStamp%.log''' TextToWrite: $'''%TimeStamp%: %Log_Message%''' AppendNewLine: True IfFileExists: File.IfFileExists.Append Encoding: File.FileEncoding.UTF8
I would then have another sub-flow that gets the last error like this:

And then I would encapsulate my code in an On block error action that calls both of those sub-flows on error:

While for normal non-error messages, I'd simply call the LogToFile sub-flow whenever I want to log anything:

That is basically the recommended sequence for logging in PAD, but then you can choose what type of files to use. The above is a simplified version I use in demos, while in PROD I would normally do a JSON-formatted log. Some people prefer CSV instead.
-------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
I also provide paid consultancy and development services using Power Automate. If you're interested, DM me and we can discuss it.