title: Serilog - With AppSettings Config how do I configure Sub Loggers & Include Certain Namespaces only?
body: <p><br/>
  I am trying to setup Serilog in a CMS that has some default logging configuration setup that we define as the CMS, however allowing developers using the CMS to extend and configure there own logging requirements by using the Serilog AppSettings Nuget package - <a href="https://github.com/serilog/serilog-settings-appsettings" rel="nofollow noreferrer">https://github.com/serilog/serilog-settings-appsettings</a></p>
  
  <p>I have some of this working and able to configure other Sinks in an external configuration file the problem I have and need help with, is how do I let developers configure a file sink to generate a txt logile that only includes their namespace?</p>
  
  <p>With a C# class I know I can create a sub-logger and then use a Filter like so
  <code>.Filter.ByIncludingOnly(Matching.FromSource("DevelopersNamespace"))</code> but using the Serilog Analyzer VS Extension - <a href="https://github.com/Suchiman/SerilogAnalyzer" rel="nofollow noreferrer">https://github.com/Suchiman/SerilogAnalyzer</a> it cannot generate an example XML AppSettings configuration.</p>
  
  <p>Here is a copy of my Logger Configuration in C#</p>
  
  <pre><code>Serilog.Debugging.SelfLog.Enable(msg =&gt; System.Diagnostics.Debug.WriteLine(msg));
  
  //Set this environment variable - so that it can be used in external config file
  //add key="serilog:write-to:RollingFile.pathFormat" value="%BASEDIR%\logs\log-{Date}.txt" /&gt;
  Environment.SetEnvironmentVariable("BASEDIR", AppDomain.CurrentDomain.BaseDirectory, EnvironmentVariableTarget.Process);
  
  Log.Logger = new LoggerConfiguration()
      .MinimumLevel.Debug() //Set to highest level of logging (as any sinks may want to restrict it to Errors only)
      .Enrich.WithProcessId()
      .Enrich.WithProcessName()
      .Enrich.WithThreadId()
      .Enrich.WithProperty("AppDomainId", AppDomain.CurrentDomain.Id)
      .Enrich.WithProperty("AppDomainAppId", HttpRuntime.AppDomainAppId.ReplaceNonAlphanumericChars(string.Empty))
      .Enrich.With&lt;Log4NetLevelMapperEnricher&gt;()
  
      //Main .txt logfile - in similar format to older Log4Net output
      //Ends with ..txt as Date is inserted before file extension substring
      .WriteTo.File($@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog.{Environment.MachineName}..txt",
          rollingInterval: RollingInterval.Day,
          restrictedToMinimumLevel: LogEventLevel.Debug,
          retainedFileCountLimit: null, //Setting to null means we keep all files - default is 31 days
          outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss,fff} [P{ProcessId}/D{AppDomainId}/T{ThreadId}] {Log4NetLevel}  {SourceContext} - {Message:lj}{NewLine}{Exception}")
  
      //.clef format (Compact log event format, that can be imported into local SEQ &amp; will make searching/filtering logs easier)
      //Ends with ..txt as Date is inserted before file extension substring
      .WriteTo.File(new CompactJsonFormatter(), $@"{AppDomain.CurrentDomain.BaseDirectory}\App_Data\Logs\UmbracoTraceLog.{Environment.MachineName}..json", 
          rollingInterval: RollingInterval.Day, //Create a new JSON file every day
          retainedFileCountLimit: null, //Setting to null means we keep all files - default is 31 days
          restrictedToMinimumLevel: LogEventLevel.Debug)
  
      //Read any custom user configuration of logging from serilog config file
      .ReadFrom.AppSettings(filePath: AppDomain.CurrentDomain.BaseDirectory + @"\config\serilog.config")
      .CreateLogger();
  </code></pre>
  
  <p>Here is an example of the AppSettings configuration file that users will be able to modify their own sinks with.</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8" ?&gt;
  &lt;configuration&gt;
      &lt;appSettings&gt;
          &lt;!-- Controls log levels for all sinks (Set this higher than child sinks) --&gt;
          &lt;add key="serilog:minimum-level" value="Verbose" /&gt;
  
          &lt;!-- Write to a user log file --&gt;
          &lt;add key="serilog:using:File" value="Serilog.Sinks.File" /&gt;
          &lt;add key="serilog:write-to:File.path" value="%BASEDIR%\logs\warren-log.txt" /&gt;&lt;!-- Can we do a relative path to website ? --&gt;
          &lt;add key="serilog:write-to:File.restrictedToMinimumLevel" value="Debug" /&gt; 
          &lt;add key="serilog:write-to:File.retainedFileCountLimit" value="32" /&gt; &lt;!-- Number of log files to keep (or remove value to keep all files) --&gt;
          &lt;add key="serilog:write-to:File.rollingInterval" value="Day" /&gt; &lt;!-- Create a new log file every Minute/Hour/Day/Month/Year/infinite --&gt;
  
          &lt;!-- TODO: How do I filter the file sink for customer to their own namespace ?? --&gt;
  
      &lt;/appSettings&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>I am open to ideas and suggestions on how I can achieve this with a goal of allowing developers to configure their own sinks and to optionally filter to their own namespace if they wish to (as I doubt users will want to write their own sink code)</p>