Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Hi , All

 

I have a problem . I want to save every operation into Log file. I have "Start", "working" form.

 

But strange thing is from "Start" form it writes into Log file and from "Working" form it does not write anything,

 

Can somebody help me-

 

this is a code

in module WriteLog function declared PUBLIC

 

Public Sub WriteLog(ByVal text1 As String, ByVal Text2 As String)

               If Not System.IO.Directory.Exists(CurDir() + "\sources\Logs\") Then
                       System.IO.Directory.CreateDirectory(CurDir() + "\sources\Logs\")

               End If

               Dim myLogName As String = CurDir() + "\sources\Logs\Running.log"

               If System.IO.File.Exists(myLogName) Then
                       Dim FI As New System.IO.FileInfo(myLogName)

                       If FI.Length > 100000 Then
                               Dim dS As String = Date.Now.Today.ToShortDateString
                               dS = dS.Replace(".", "")
                               Dim dT As String = DateTime.Now.ToLongTimeString
                               dT = dT.Replace(":", "")
                               System.IO.File.Move(myLogName, CurDir() + "\sources\Logs\Log_" + dS + dT + ".bak")
                       End If
               End If

               Try
                       Dim sw As System.IO.StreamWriter = New System.IO.StreamWriter(myLogName, True)

                       sw.WriteLine(Date.Now.Today.ToShortDateString + " " + DateTime.Now.ToLongTimeString + " : " + text1 + ControlChars.Tab + ControlChars.Tab + Text2)

                       sw.Close()

               Catch ex As Exception
                       MsgBox(ex.Message)
               End Try
       End Sub

 

in Start form

WriteLog("Patient " & mPersonID & " has Logged in ", "DONE")

 

in Working form

 

WriteLog("Basci stimulation Started", "Done")           

Posted

solution

 

At the end I found a problem . Because of "Curdir" function . It gives me a current directory. But In "Working" form I use openFileDiaglog. It changes current folder name . So that after "working" form "Curdir" retunrs me openned folder name.

 

Therefore Please be careful use "CurDir" after FileOPenDialogBox

 

Thanks,

Erdenemandal

  • Administrators
Posted

You may be better of using the .Net version of CurDir anyway

System.IO.Directory.GetCurrentDirectory()
'or
Environment.CurrentDirectory

If the folders are always going to be relative to the running application's path then

Application.ExecutablePath

maybe a better choice.

Posting Guidelines FAQ Post Formatting

 

Intellectuals solve problems; geniuses prevent them.

-- Albert Einstein

Posted
What also helps is setting the RestoreDirectory property of the file dialog. It ensures that the current directory, after the dialog is closed, is restored to the location it was pointing before the dialog was opened.
Nothing is as illusive as 'the last bug'.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...