Skip to content

Optimize NLogLogger #239

Description

@snakefoot

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);
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions