title: Log File Depending on Property Selected in Class Attribute
body: <p>I want to create a per file logger which will log to files depending on type and the specifications of an attribute on that type, but I'm having difficulty doing it in a trivial manner.</p>
  
  <p>So I would enumerate through all types using a LogOutputAttribute</p>
  
  <pre><code>[System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
  public sealed class LogOutputAttribute : Attribute
  {
      public string[] Directories { get; set; }
  
      public LogOutputAttribute(params string[] directories)
      {
          Directories = directories;
      }
  
      public string ResolveOnMember { get; set; }
  }
  </code></pre>
  
  <p>Which is used as such:</p>
  
  <pre><code>[LogOutput("Logging", "Subjects", ResolveOnMember = nameof(Name))]
  public class LogSubject
  {
      public string Name { get; set; }
  }
  </code></pre>
  
  <p>And in my logger creation:</p>
  
  <pre><code>var dirs = new string[] { Path.GetDirectoryName("Logging") };
  var logFileName = "Main";
  
  var config = new LoggerConfiguration();
  
  foreach (var type in types)
  {
      if (type.GetCustomAttributes(typeof(LogOutputAttribute), true).SingleOrDefault() is LogOutputAttribute logOutput)
      {
          dirs = logOutput.Directories;
          logFileName = logOutput.ResolveOnMember;
      }
  
      var path = Path.Combine(dirs);
      Directory.CreateDirectory(path);
      Console.WriteLine("Writing to " + path);
  
      config = config.WriteTo.Logger(lc =&gt; lc
          .Filter.ByIncludingOnly(Matching.FromSource(type.FullName))
          .WriteTo.Map(logFileName, "unknown", (n, wt) =&gt;
          {
              path = Path.Combine(path, n + ".txt");
              wt.File(path, rollingInterval: RollingInterval.Day);
          }));
  }
  
  var logger = config.CreateLogger();
  </code></pre>
  
  <p>I'd like to enrich the message with the property name and value chosen by the attribute <strong>ResolveOnMember</strong> when the log comes through so it would be processed by the mapping in <strong>.Map</strong>, not sure how or if it's possible to do this.</p>
  
  <p>Another way would be using <strong>ForContext</strong> using <strong>contextual DI injection</strong>,
  I use Dryioc which would look like </p>
  
  <pre><code>container.Register&lt;Logging.ILogger&gt;(
      made: Made.Of(() =&gt; LoggerFactory.GetLogger(new LogContext("SourceContext", Arg.Index&lt;Type&gt;(0))), r =&gt; r.Parent.ImplementationType),
      setup: Setup.With(condition: r =&gt; r.Parent.ImplementationType != null));
  </code></pre>
  
  <p>But I can't see how to insert the value the chosen <strong>ResolveOnMember</strong> from here.</p>