Skip to content

add Logger.LogWrite event #745

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Feb 23, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion src/ExchangeSharp/Utility/Logger.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/*
/*
MIT LICENSE

Copyright 2017 Digital Ruby, LLC - http://www.digitalruby.com
Expand Down Expand Up @@ -94,13 +94,21 @@ public enum LogLevel
None = Off
}

public class LoggerEvent
{
public LogLevel level;
public string text;
public object[] args;
}

/// <summary>
/// ExchangeSharp logger. Will never throw exceptions.
/// Currently the ExchangeSharp logger uses NLog internally, so make sure it is setup in your app.config file or nlog.config file.
/// </summary>
public static class Logger
{
private static readonly NLog.Logger logger;
public static event Action<LoggerEvent> LogWrite;

static Logger()
{
Expand Down Expand Up @@ -253,6 +261,7 @@ public static void Write(LogLevel level, string text, params object[] args)
text = string.Format(text, args);
}
logger?.Log(GetNLogLevel(level), text);
LogWrite?.Invoke(new LoggerEvent() { level = level, text = text, args = args });
}
catch
{
Expand Down