Last active
August 29, 2015 14:24
-
-
Save elpatron68/a37a8fa12919681f0786 to your computer and use it in GitHub Desktop.
NLog change target programmatically (VB.NET)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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