前端之家收集整理的这篇文章主要介绍了
VB.NET 写日志文件,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
''' <summary>
''' 写日志
''' </summary>
''' <param name="msg">日志内容</param>
''' <param name="context">上下文对象</param>
''' <remarks></remarks>
Sub WriteLog(msg As String,Optional context As System.Web.HttpContext = Nothing)
Dim filepath As String = ""
If context Is Nothing Then
filepath = Me.LogFilePath
Else
filepath = context.Server.MapPath("..") + "\File\LogFile\"
End If
filepath &= Now.ToString("yyyyMMdd") & ".txt"
Dim content As String
If context IsNot Nothing Then
content = "<-------------异常时间:" & Now.ToString("yyyy-MM-dd HH:mm:ss") & _
Chr(13) & msg & "来源:" & context.Request.Url.ToString & _
"错误信息:" & context.Error.Message & _
Chr(13) & "错误详情:" & Chr(13) & context.Error.StackTrace & Chr(13) & _
"--------------->" & Chr(13)
Else
content = "异常时间:" & Now.ToString("yyyy-MM-dd HH:mm:ss") + Chr(13) & msg & Chr(13)
End If
File.AppendAllText(filepath,content)
End Sub
原文链接:https://www.f2er.com/vb/256805.html