以下代码对网站上的一位用户有效。 但是,一旦有多个用户同时开始登录,Serilog将开始丢失日志文件条目。有人知道我想念的吗?
Public Class cLogger
Public Shared gSerilogger As ILogger = Nothing
Public Shared gblSeriLock As New Object
Public Shared Sub DoSerilog(ByVal sLogMessage As String)
SyncLock gblSeriLock
If gSerilogger Is Nothing Then
gSerilogger = New LoggerConfiguration().WriteTo.Console().WriteTo.File("d:\Logfiles\SERI.log").CreateLogger()
End If
gSerilogger.Information(sLogMessage)
End SyncLock
End Sub
End Class
用法示例:
cLogger.DoSerilog("Test")