TorSharp icon indicating copy to clipboard operation
TorSharp copied to clipboard

Custom Log output

Open ArcadeArchie opened this issue 4 years ago • 7 comments

Is there already a way to redirect the console output for custom logging?

ArcadeArchie avatar Jun 19 '20 07:06 ArcadeArchie

Great idea! Currently there is no way to do it but it could be added without much difficulty. The VirtualDesktopToolRunner might be a little harder since Windows API are directly p/invoked but it should be do-able. What sort of interface so you want?

Would something like this work?

public interface ITorSharpLogger
{
    void OnOutput(string data);
    void OnError(string data);
}

And you pass in an implementation of this ITorSharpLogger via TorSharpSettings.Logger?

None of this is implemented yet but I want to see what specifically you are thinking could work.

joelverhagen avatar Jun 19 '20 16:06 joelverhagen

Doing it with an Inteface isnt such a bad idea but i think doing it over events would be better, like:

    interface ITorSharpProxy
    {
        ....
        public event EventHandler<LogEventArgs> OnOutput;
        public event EventHandler<ErrEventArgs> OnError;
        ....
    }


ITorSharpProxy proxy = new TorSharpProxy();
proxy.OnOutput += OnOutput;
proxy.OnError += OnError;

or a mix between the two.

ArcadeArchie avatar Jun 20 '20 16:06 ArcadeArchie

Sounds good! No clue when I will get to this. It sounds like a solid idea though and it seems quite doable as a community contribution.

joelverhagen avatar Jun 20 '20 17:06 joelverhagen

This is a great project, but I'm also missing this feature, so I decided to implement in on my own!

I committed some changes as you can see on my fork. But I'm having troubles, so I decided to ask a question on StackOverflow, any help is appreciated! Thanks!

https://stackoverflow.com/questions/63345753/redirect-stdout-and-stderr-from-process-created-with-winapi

z3nth10n avatar Aug 10 '20 18:08 z3nth10n

Just saw this since I was looking for a way to control the output channel as well... why not implement the use of the standard .NET core ILogger interface?

developer82 avatar Jul 14 '21 06:07 developer82

Great point @developer82, this is a very reasonable API to align upon. Want to make a PR to add this capability?

joelverhagen avatar Jul 15 '21 03:07 joelverhagen

@joelverhagen downloaded the code. Will try...

developer82 avatar Jul 15 '21 06:07 developer82