Skip to content
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

Optimize NLogLogger #239

Open
snakefoot opened this issue Aug 21, 2018 · 1 comment
Open

Optimize NLogLogger #239

snakefoot opened this issue Aug 21, 2018 · 1 comment

Comments

@snakefoot
Copy link

snakefoot commented Aug 21, 2018

Add this as property to the NLogLogger-class (Use Log instead of constantly calling GetCurrentClassLogger) :

private ILogger Log { get { return _log ?? (_log = LogManager.GetCurrentClassLogger()); } }
ILogger _log;

Improve the following method:

private void SendLog(object message, LogLevel level, IDictionary<string, object> properties, Exception exception = null)
{
var propertiesLocal = properties ?? new Dictionary<string, object>();

By adding IsEnabled-check to the beginning of the SendLog-method above:

    if (!Log.IsEnabled(level))
        return;   
  
   var propertiesLocal = properties ?? new Dictionary<string, object>(); 

Introduce this new SendLog method with the following parameters (And fix all Log-methods that calls BuildProperties to instead pass ILogEntry to this new method):

void SendLog(object message, LogLevel level, ILogEntry logEntry, Exception exception = null)
{
    if (!Log.IsEnabled(level))
        return;

    SendLog(message, level, BuildProperties(logEntry), exception);
}

Modify the this SendLog-method:

private void SendLog(object message, LogLevel level, Exception exception = null)
{
SendLog(message, level, new Dictionary<string, object>(), exception);

So it becomes:

void SendLog(object message, LogLevel level, Exception exception = null)
{
    if (!Log.IsEnabled(level))
        return;

    SendLog(message, level, new Dictionary<string, object>(), exception);
}
@snakefoot
Copy link
Author

@leewadhams This will minimize the cost of logging and optimize performance.

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

No branches or pull requests

1 participant