首页 > 学院 > 开发设计 > 正文

VB.NET 写日志文件

2019-11-08 03:10:41
字体:
来源:转载
供稿:网友
''' <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


发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表