Results 1 to 2 of 2

Thread: Delphi, How to Make Log File?!

  1. #1
    Join Date
    Jul 2010
    Posts
    37

    Delphi, How to Make Log File?!

    How to make a log file in Delphi, where all done actions were recorded in text file and in the form itself?!

    For example:

    Code:
    1. APPLICATION HAS BEEN STARTED [TIME]
    2. WEB-SITE HAS BEEN OPENED [TIME]
    3. WEB-SITE HAS BEEN CLOSED [TIME]
    4. APPLICATION HAS BEEN CLOSED [TIME]

  2. #2
    Join Date
    Dec 2007
    Posts
    2,291

    Re: Delphi, How to Make Log File?!

    You could try to LOG all exceptions to a simple text file. Drop a TApplication component on the main form of your application and handle the OnException event. The code below, provides one such logging technique. Each exception is added to a simple ASCII file with the date and time of the exception (along with the exception's message):

    Code:
    procedure TForm1.ApplicationEvents1Exception(
       Sender: TObject;
       E: Exception) ;
    var
       ErrorLogFileName : string;
       ErrorFile : TextFile;
       ErrorData : string;
    begin
       ErrorLogFileName := ChangeFileExt(Application.ExeName,'.error.log') ;
       AssignFile(ErrorFile, ErrorLogFileName) ;
    
       //either create an error log file, or append to an existing one
       if FileExists(ErrorLogFileName) then
         Append(ErrorFile)
       else
         Rewrite(ErrorFile) ;
    
       try
         //add the current date/time and the exception message to the log
         ErrorData := Format('%s : %s',[DateTimeToStr(Now),E.Message]) ;
         WriteLn(ErrorFile,ErrorData) ;
       finally
         CloseFile(ErrorFile)
       end;
    
       //Show the exception
       Application.ShowException(E) ;
    end;
    More information can be found here.

Similar Threads

  1. make file name list in excel using batch file
    By shibinpanayi in forum Windows Software
    Replies: 1
    Last Post: 04-06-2011, 03:44 AM
  2. How to make a .INF file?
    By Esmel in forum Software Development
    Replies: 6
    Last Post: 28-08-2010, 12:33 PM
  3. Replies: 3
    Last Post: 16-07-2009, 01:29 PM
  4. Delphi shortcut make
    By Hakon in forum Software Development
    Replies: 5
    Last Post: 27-03-2009, 09:47 PM
  5. How to make exe file from c++
    By Dhyanesh in forum Windows Software
    Replies: 4
    Last Post: 02-02-2009, 11:42 AM

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Page generated in 1,713,880,492.94647 seconds with 17 queries