send via email only new logs entries

Hi.
On a server I have an application which writes an entry in a log file (txt file) every time an event occours. The log written are all of the same type. This is the entry:

time and data/ field1/field2


Now . I want to create another small application (as win service)
 which can read the file one time per day (i.e during the night at 2 am when I know for sure that the first application won't write into the log file) and sends all the new entry to a specific mail recepient as one shot. So the second application should know from where start by keeping track of time and data field.

Can you help me with this small project?


jaja2005Asked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Geert GOracle dbaCommented:
just use the equivalent of tail on windows:
http://tailforwin32.sourceforge.net/
0
jaja2005Author Commented:
Unfortunatly is C++
0
Geert GOracle dbaCommented:
all the groups you assigned to this question are "delphi"
0
Rowby Goren Makes an Impact on Screen and Online

Learn about longtime user Rowby Goren and his great contributions to the site. We explore his method for posing questions that are likely to yield a solution, and take a look at how his career transformed from a Hollywood writer to a website entrepreneur.

jaja2005Author Commented:
How to achive that using pascal.?. :-(
0
Geert GOracle dbaCommented:
see snippet to get changed log lines


procedure TForm1.Tail(FileName: string; Lines: TStrings; LimitLines: Integer = 0);

  function OpenReg: TRegistry;
  const
    CompanyName = 'jaja2005';
    AppName     = 'Tail';
  begin
    Result := TRegistry.Create(KEY_ALL_ACCESS);
    Result.RootKey := HKEY_CURRENT_USER; // you may want to use Local machine on a server
    Result.OpenKey(Format('Software\%s\%s', [CompanyName, AppName]), True);
  end;

  function ReadRegInt(ParamName: string; Default: integer = 0): integer;
  begin
    Result := Default;
    with OpenReg do
    try
      if ValueExists(ParamName) then
        Result := ReadInteger(ParamName);
    finally
      Free;
    end;
  end;

  procedure WriteRegInt(ParamName: string; Value: integer);
  begin
    with OpenReg do
    try
      WriteInteger(ParamName, Value);
    finally
      Free;
    end;
  end;

var
  Start: Integer;
  F: TFileStream;
begin
  if FileExists(FileName) then
  begin
    Lines.BeginUpdate;
    try
      Start := ReadRegInt(Format('filesize_%s', [FileName]));
      F := TFileStream.Create(FileName, fmOpenRead);
      try
        F.Seek(Start, soFromBeginning);
        Lines.LoadFromStream(F);
        WriteRegInt(Format('filesize_%s', [FileName]), F.Size);
      finally
        F.Free;
      end;
    finally
      Lines.EndUpdate;
    end;
  end;
end;


procedure TForm1.Button1Click(Sender: TObject);
begin
  Tail('c:\temp\test.txt', Memo1.Lines);
end;

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
jaja2005Author Commented:
how to use it? Can you send the project file? :-(
0
Geert GOracle dbaCommented:
eh ?

just create a file c:\temp\test.txt
add some lines and save
then run the above code

then add some more lines to the file
and run the above code again

the memo will contain the newly added lines

only appending works
0
jaja2005Author Commented:
Thx.
Why it uses Tregistry Class?
0
jaja2005Author Commented:
it works. Great. can you explain me in a few word how it uses the registry?
0
jaja2005Author Commented:
Shouldn't be a big task to covert this small application in a windows service right?
0
Geert GOracle dbaCommented:
it uses the registry to save the last size of the file it read
the next time it first checks this size and reads on from that point

hmmm come to think of it, i haven't put a check in, if this goes past the file size
emptying the file would not show anything anymore

change this code:
F := TFileStream.Create(FileName, fmOpenRead);
try
  F.Seek(Start, soFromBeginning);

to
F := TFileStream.Create(FileName, fmOpenRead);
try
  if (Start > 0) and (Start > F.Size) then
    Start := 0;
  F.Seek(Start, soFromBeginning);
0
Geert GOracle dbaCommented:
to a windows service ?

well not really
i never actually do that, i have some apps like this running on database servers

what i do, is add a windows schedular task,
and set properties to run when user is logged off and max priviliges

then i don't need to bother with converting it to a service
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Delphi

From novice to tech pro — start learning today.