Jump to content

Recommended Posts

Posted

Hi Guys,

I'm building an application using AutoIt. I wrote a little function to generate a log-file for each script which can be run within the app. Furthermore I wrote different looging functions, which can be used to log different things (e.g. errors, warnings, etc...). Problem ist this:

- 1st time whe I open the generated log file and write something into it - it works fine... So, I open the file, write and close it again. So far, so good!

But when I open the same file again and try to write something else inside of it, the 1st line, written before, gets deleted...

Here's my code:

Func LogError($sLogFilePath, $sLogFileName, $sErrorMessage)
    Local $LogTime = @HOUR & ':' & @MIN & ':' & @SEC

    ;~ open file
    Local $hFileOpen = FileOpen($sLogFilePath & $sLogFileName, $FO_READ + $FO_OVERWRITE)
    
    ;~ handle errors
    If $hFileOpen = -1 Then
        MsgBox(16, '', 'Fehler beim öffnen des Log-Files in WriteErrorLog()!')
    EndIf
    
    ;~ write into log file
    FileWriteLine($hFileOpen, 'Error: ' & $LogTime & ' | ' & 'Reason: ' & $sErrorMessage & @CRLF)
    FileClose($hFileOpen)
EndFunc

Nearly the same code I have for other log-types...

What can I do to add every new log to the end of the file? Or maybe there exists a function which I can use to get the number of already written line? In this case I could use FileWriteToLine()...

Would be very happy, if somebody could help me to solve this.

 

Kind Regards,

Mic

Posted

Well, the flags

$FO_READ + $FO_OVERWRITE

are creating your problem as the help file says "$FO_OVERWRITE (2) = Write mode (erase previous contents)" You should try  $FO_APPEND (1).

have fun,

Marc

 

Any of my own codes posted on the forum are free for use by others without any restriction of any kind. (WTFPL)

  • Developers
Posted

Moved to the appropriate forum, as the Developer General Discussion forum very clearly states:

Quote

General development and scripting discussions.


Do not create AutoIt-related topics here, use the AutoIt General Help and Support or AutoIt Technical Discussion forums.

Moderation Team

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...