28 lines
1.3 KiB
VB.net
28 lines
1.3 KiB
VB.net
Public Class ClassNLog
|
|
Public Shared Function GetLogPathFor(moduleName As String)
|
|
Dim localAppData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData)
|
|
Return IO.Path.Combine(localAppData, "Digital Data", "UserManager", "Log")
|
|
End Function
|
|
|
|
Public Shared Function GetLoggerConfigFor(moduleName As String)
|
|
Dim loggerConfig = New NLog.Config.LoggingConfiguration()
|
|
Dim logFileName = Environment.UserName & "-${date:format=yyyy-MM-dd}.log"
|
|
Dim logPath As String = IO.Path.Combine(GetLogPathFor(moduleName), logFileName)
|
|
|
|
Dim logFileInfo As New NLog.Targets.FileTarget("logFileInfo") With {
|
|
.FileName = logPath,
|
|
.Layout = "${longdate}|${level:uppercase=true}|${logger}|${message}"
|
|
}
|
|
|
|
Dim logFileError As New NLog.Targets.FileTarget("logFileError") With {
|
|
.FileName = logPath,
|
|
.Layout = "${longdate}|${level:uppercase=true}|${logger}|${message}|${exception:format=message}" & vbCrLf & "${exception:format=toString}"
|
|
}
|
|
|
|
loggerConfig.AddRule(NLog.LogLevel.Debug, NLog.LogLevel.Warn, logFileInfo)
|
|
loggerConfig.AddRule(NLog.LogLevel.Error, NLog.LogLevel.Fatal, logFileError)
|
|
|
|
Return loggerConfig
|
|
End Function
|
|
End Class
|