Posted By

fuzzylogic on 07/23/09


Tagged

event log tracking


Versions (?)

Who likes this?

2 people have marked this snippet as a favorite

haoji
D4RKCODE


Log Events


 / Published in: VB.NET
 

  1. Public Sub WriteToLog(ByVal Action As String, ByVal Details As String)
  2.  
  3. Dim strConn As String = System.Configuration.ConfigurationManager.ConnectionStrings("FullConnection").ConnectionString
  4. Dim MySQL As String = "insert into tEventLog(Action,Time,IPAddress,Details) values(@Action,@Time,@IPAddress,@Details)"
  5. Dim MyConn As New SqlConnection(strConn)
  6. Dim Cmd As New SqlCommand(MySQL, MyConn)
  7. Cmd.Parameters.Add(New SqlParameter("@Action", Action))
  8. Cmd.Parameters.Add(New SqlParameter("@Time", Now()))
  9. Cmd.Parameters.Add(New SqlParameter("@IPAddress", Request.UserHostAddress()))
  10. Cmd.Parameters.Add(New SqlParameter("@Details", Details))
  11. Try
  12. MyConn.Open()
  13. Cmd.ExecuteReader(System.Data.CommandBehavior.CloseConnection)
  14.  
  15. Catch ex As Exception
  16. Response.Write(ex.Message & ":WriteToLog:" & ex.ToString)
  17. End Try
  18. End Sub

Report this snippet  

You need to login to post a comment.