Skip to content

Instantly share code, notes, and snippets.

@elpatron68
Last active August 29, 2015 14:24
Show Gist options
  • Save elpatron68/a37a8fa12919681f0786 to your computer and use it in GitHub Desktop.
Save elpatron68/a37a8fa12919681f0786 to your computer and use it in GitHub Desktop.
NLog change target programmatically (VB.NET)
Imports NLog
Imports NLog.Common
Imports NLog.Targets
Imports NLog.Config
Module Module1
Private _logger As Logger
Sub Main()
Dim sToday As String = DateTime.Today.ToString("yyyy-MM-dd")
Dim FileTarget = New FileTarget() With {.FileName = sLogdir + sToday + ".log"}
Dim ConsoleTarget As New ConsoleTarget
ConsoleTarget.Layout = "${date:format=HH}:${date:format=mm}:${date:format=ss}: ${message}"
config.AddTarget("logfile", FileTarget)
config.AddTarget("console", ConsoleTarget)
Dim FileRule = New LoggingRule("*", LogLevel.Debug, FileTarget)
Dim ConsoleRule = New LoggingRule("*", LogLevel.Debug, ConsoleTarget)
config.LoggingRules.Add(FileRule)
config.LoggingRules.Add(ConsoleRule)
LogManager.Configuration = config
_logger = LogManager.GetCurrentClassLogger()
_logger.Info("Logger initialized.")
End Sub
End Module
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment