In reply to bhupeshpaliwal:
I made a few additional attempts, but did not succeed to write to the logfile.
And I thought a lot about your objective. Is this exampls a theoretical example or what is it?
If you want to use constructs like this in a project it violates one of the basic UVM implementation rules: “write your code as simple as possible. A 3rd person should understand your implementation without big effort”.