Skip to content

Add intergration seam to Logger#172

Open
KevM wants to merge 1 commit intosta:masterfrom
KevM:logger-seam
Open

Add intergration seam to Logger#172
KevM wants to merge 1 commit intosta:masterfrom
KevM:logger-seam

Conversation

@KevM
Copy link
Copy Markdown

@KevM KevM commented Oct 26, 2015

In our usage of websocket-sharp we need to integrate our logging infrastructure with websocket-sharp's. This PR adds a seam which allows the Logger implementation to be swapped out. Existing users are not affected.

Downstream users wishing to use their own logger would simply use the Log setter:

var webSocket = new WebSocket("ws://websocket.org/echo")
{
  Log = new Log4NetWebSocketLogger()
};

Example integration

Below is an integration example for plain Log4Net.

public class Log4NetWebSocketLogger : IWebSocketLogger
{
    private readonly ILog _log;

    public Log4NetWebSocketLogger()
    {
        _log = LogManager.GetLogger(typeof(WebSocket));
    }

    public void Debug(string message)
    {
        _log.Debug(message);
    }

    public void Error(string message)
    {
        _log.Error(message);
    }

    public void Fatal(string message)
    {
        _log.Fatal(message);
    }

    public void Info(string message)
    {
        _log.Info(message);
    }

    public void Trace(string message)
    {
        _log.Debug(message);
    }

    public void Warn(string message)
    {
        _log.Warn(message);
    }
}

Thank you for your consideration. Let me know if there is anything I can do to improve this PR.

@sta
Copy link
Copy Markdown
Owner

sta commented Oct 28, 2015

Hello there, thanks for your pull request.

I would like to merge this fix, but how does this change the log level (, set the file output, and change the output behavior)?

@KevM
Copy link
Copy Markdown
Author

KevM commented Nov 4, 2015

Hello back, It does not change the log level or any existing behavior. This PR simply exposes a seam for users to change out the built in logger with their own.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants