title: Nlog Email Target Programmatically
body: <p>I have a program which uses the NLog logging library. I have a config file with targets and rules, I add programmatically some rules to write to a database. Until now everything works fine. </p>
  
  <p>Now I like to change the config programmatically. I use <code>SimpleConfigurator</code></p>
  
  <pre><code>NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(target, LogLevel.Fatal)
  </code></pre>
  
  <p>my VB Code looks like that:</p>
  
  <pre><code>Dim target As MailTarget = New MailTarget()
  target.Name = "Mailing"
  target.Html = True
  target.Body = "${message}"
  target.SmtpServer = EmailSending.SendingServer
  target.From = EmailSending.EmailSender
  target.Encoding = System.Text.Encoding.UTF8
  target.[To] = EmailSending.EmailReceiver
  target.EnableSsl = EmailSending.EnableSSl
  target.SmtpPort = EmailSending.sendingPort
  target.SmtpUserName = EmailSending.EmailSender
  target.SmtpPassword = EmailSending.EmailsenderPw
  </code></pre>
  
  <p>and now adding this stuff to the config:</p>
  
  <pre><code>LogManager.Configuration.AddTarget("Mailing", target)
  Dim MailTarget As NLog.Targets.Target = LogManager.Configuration.FindTargetByName("Mailing")
  Dim loggerRule As NLog.Config.LoggingRule = New NLog.Config.LoggingRule("*", LogLevel.Fatal, MailTarget)
  LogManager.Configuration.LoggingRules.Add(loggerRule)
  </code></pre>
  
  <p>The new target and rule works, but the "simpleconfigurator" clear previous configuration. How do I prevent that?
  Thanks for help!</p>