Thursday, October 28, 2010

How do I create a log file in VB 2008?

In VB 2008, I know how to make a basic program, but to access it I can create a log in for users but if someone tried to hack the system .e.g. entering the admin account and they got it Wrong how do I make it that logs the pc down and time and date on a text file?How do I create a log file in VB 2008?
Imports System.IO ''Declare namespace



in the click event of the validate button you need to add



if txtPassword.text = ';this is my password'; then

frmSecretMiracleForm.show()

me.close()

else

Dim iFreeFile As Object, sPath As String

iFreeFile = FreeFile()

sPath = ';C:\ProgramLog.txt';

PrintLine(iFreeFile, ';Incorrect password entered: '; %26amp; now)

FileClose(iFreeFile)

End if



If you wanted to add which username was logged in at the time you could add the following line in too:



PrintLine(iFreeFile, ';Logged in user: '; %26amp; System.Environment.UserName)

How do I create a log file in VB 2008?
Public Sub Debug(ByVal E As String, ByVal DL As DebugLevel)

If DL %26gt;= DebugLevel Then

Dim Writer As New IO.StreamWriter(App_Path %26amp; ';\Debug.txt';, True)

Dim ErrorString As String = ';('; %26amp; Date.Now %26amp; ';) ';

Select Case DL

Case Data.DebugLevel.Required



Case Data.DebugLevel.Critical

ErrorString = ErrorString %26amp; ';**** CRITICAL Error: ';

Case Data.DebugLevel.General

ErrorString = ErrorString %26amp; ';Error: ';

Case Data.DebugLevel.Informational

ErrorString = ErrorString %26amp; ';Notice: ';

Case Data.DebugLevel.Severe

ErrorString = ErrorString %26amp; ';Severe Error: ';

End Select

ErrorString = ErrorString %26amp; E

Writer.WriteLine(ErrorString)

Writer.Close()

End If

End Sub



Public Enum DebugLevel As Byte

Informational

General

Severe

Critical

Off

Required

End Enum

No comments:

Post a Comment