Css的HTML错误日志
本文关键字:日志 错误 HTML Css | 更新日期: 2023-09-27 18:20:22
我有一段闲置的代码,用来用visual basic记录错误。有什么方法可以为C#创建这样的错误日志吗?
Private Sub writelog(ByVal title As String, ByVal data As String, ByVal isError As Boolean, ByVal logname As String)
If write_log = True Then
Try
Dim data_con As String
data_con = "<table border=""1"" bordercolor=""#0099FF"" style=""background-color:#FFFFFF"" width=""100%"" cellpadding=""2"" cellspacing=""2"">" & vbCrLf & _
"<tr>" & vbCrLf
If isError = True Then
data_con = data_con & "<td WIDTH=""15%"" bgcolor=""#FFFF99"" bordercolor=""RED""><b><FONT COLOR=""RED"">" & title & "</font></b></td>" & vbCrLf
data_con = data_con & "<td WIDTH=""70%"" bgcolor=""#FFFF99"" bordercolor=""RED"">" & data & "</td>" & vbCrLf & _
"<td WIDTH=""15%"" bgcolor=""#FFFF99"" bordercolor=""RED"">" & DateAndTime.Now & "</td>" & vbCrLf & _
"</tr></table>"
Else
data_con = data_con & "<td WIDTH=""15%""><b><FONT COLOR=""GREEN"">" & title & "</font></b></td>" & vbCrLf
data_con = data_con & "<td WIDTH=""70%"">" & data & "</td>" & vbCrLf & _
"<td WIDTH=""15%"">" & DateAndTime.Now & "</td>" & vbCrLf & _
"</tr></table>"
End If
My.Computer.FileSystem.WriteAllText(My.Application.Info.DirectoryPath & "'" & logname & ".html", data_con & vbCrLf, True)
Catch ex As Exception
End Try
End If
End Sub
private void writelog(string title, string data, bool isError, string logname) {
if ((write_log == true)) {
try {
string data_con;
data_con = ("<table border='"1'" bordercolor='"#0099FF'" style='"background-color:#FFFFFF'" width='"100%'" cellpadding='"2'"" +
" cellspacing='"2'">" + ("'r'n" + ("<tr>" + "'r'n")));
if ((isError == true)) {
data_con = (data_con + ("<td WIDTH='"15%'" bgcolor='"#FFFF99'" bordercolor='"RED'"><b><FONT COLOR='"RED'">"
+ (title + ("</font></b></td>" + "'r'n"))));
data_con = (data_con + ("<td WIDTH='"70%'" bgcolor='"#FFFF99'" bordercolor='"RED'">"
+ (data + ("</td>" + ("'r'n" + ("<td WIDTH='"15%'" bgcolor='"#FFFF99'" bordercolor='"RED'">"
+ (DateAndTime.Now + ("</td>" + ("'r'n" + "</tr></table>")))))))));
}
else {
data_con = (data_con + ("<td WIDTH='"15%'"><b><FONT COLOR='"GREEN'">"
+ (title + ("</font></b></td>" + "'r'n"))));
data_con = (data_con + ("<td WIDTH='"70%'">"
+ (data + ("</td>" + ("'r'n" + ("<td WIDTH='"15%'">"
+ (DateAndTime.Now + ("</td>" + ("'r'n" + "</tr></table>")))))))));
}
File.WriteAllText(Path.Combine("Put here your log directory path",logname), data_con);
}
catch (Exception ex) {
}
}
}