title: Custom implementation of ILogger
body: <p>In my project I often add prefixes to my log messages. </p>
  
  <p>Currently I am doing this with</p>
  
  <pre class="lang-cs prettyprint-override"><code>      logger.LogDebug(prefix + " some message");
  </code></pre>
  
  <p>I thought it would be a good way to implement a custom logger where I set the prefix and the logger itself attaches it every time it logs something.</p>
  
  <p>So I created my custom logger class and implemented the ILogger interface. But I do not understand how to use the </p>
  
  <pre class="lang-cs prettyprint-override"><code>    public void Log&lt;TState&gt;(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func&lt;TState, Exception, string&gt; formatter)
  </code></pre>
  
  <p>method to add the prefix (which is a member of the custom logger class).</p>
  
  <p>My full code is:</p>
  
  <pre class="lang-cs prettyprint-override"><code>      public class CustomLogger : ILogger
        {
  
          private readonly ILogger _logger;
          private string _logPrefix;
  
          public CustomLogger(ILogger logger)
          {
            _logger = logger ?? throw new ArgumentNullException(nameof(logger));
          _logPrefix = null;
          }
  
          public ILogger SetLogPrefix(string logPrefix)
          {
            _logPrefix = logPrefix;
            return this;
          }
  
          public IDisposable BeginScope&lt;TState&gt;(TState state)
          {
            return _logger.BeginScope(state);
          }
  
          public bool IsEnabled(LogLevel logLevel)
          {
            return _logger.IsEnabled(logLevel);
          }
  
          public void Log&lt;TState&gt;(LogLevel logLevel, EventId eventId, TState state, Exception exception, Func&lt;TState, Exception, string&gt; formatter)
          {
            _logger.Log(logLevel, eventId, state, exception, formatter);
          }
  
        }
  </code></pre>