Well, this is my working name of the project – yeti syslog.
I decided don't use any big third-party components. Most of code is Delphi 7 native.
So, the work consist of 3 parts – the syslog service, the interface part, and the installer.
Yes, not all parts are completed. Therefore any part can be changed, may be not whole, but some things.
Consist of the form with 3 pages (4th page – temporary for testing purposes). Also the tray icon, that allow to see the settings and change them.
All settings are saved into the registry – key HKEY_LOCAL_MACHINE
The service is working from registry settings, it doen't save anything into registry (although for now I saved the time when last logs was ent to syslog).
I use recent InnoSetup installation utility.
The installer – install both interface part and services into the system.
Current variant install the interface part.
Contain two classes that read data from registry into the properties.
Also it save changed variable back into registry.
This unit is used by both parts – by the interface and the service.
The interface form that consist of 3 pages based on initial 3 gifs.
The service unit
Simple component with tray icon + popup menu. Was used it in some my projects, not well commented, but working fine.
Used as syslog facility, email about bugs, etc. For now – it write messages into the windows/temp directory, file “test_output.txt”. (note: in Win 2008 R2 – a 'temp' directory is under /users/…/application data/)
Testing in Windows 2008 Server R2 64-bit – both *.EXE being compiled by Delphi 7.0 – not working correct with eventlog, but everything fine after recompile them in the Delphi 2007. Resume – use Delphi 2007 to compile the final release.
Many things were refined. Now we can see that this work is completed by 85%.
When the service read messages from the eventlogNT, and lines from monitored files – it should send them out to syslog. We can define this process as a “transcation”. If transaction fail – the program will not update the Last_events[k] and lastsize[k] variables.
After 'try_cnt' fails – it sends out an email about this on defined email if any.
Successful – the program update the values:
All messages from the eventlogNT are read in the reverse order (from latest back to oldest), result – the TStringList variable. On successful transaction – it takes the DateTime “Generated” value from the latest message and place it into the “Last_events” variable.
Ok, as I mentioned before, every monitored file has the last size – the length of the file in bytes. The program is thinking about the file size is grows up. Every time the program open the file, seek into the position of previous size, and read all new bytes into the “buffer” in the binary mode. The it split this buffer into TStringList variable by #10 and #13 (usual windows line breaks).
In the case if last_size less then the current size – the program thinks about the monitored file was rewritten from scratch and read all lines from their beginning.
Inside the code were added the compiler directives on the (“$IF CompilerVersion >= 18.5”) – to have the same code both for Delphi 7 and Delphi 2007. Yes, in these IDE some parameters where renamed. The Indy TIdSyslog component was changed in the Delphi 2007 edition.
Also recent TIdSyslog component has the ipv6 support when old had not.
Note: I don't found any ready-to-use freeware Delphi component that support the TCP protocol for syslog connections. Therefore if you have any – send me it to use. Otherwise I can not to implement TCP for syslog, only UDP + ipv4/ipv6. I'm an usual system programmer, do not understand details of the protocols UDP/TCP and how to program them.
About Delphi 2010 – I assume you should compile the code in the compatible with old Delphi mode because of there are a lot of code that use 'string' type for low-level binary operations and this code is thinking about in this 'string' one byte = one character.
The same as 1 'char' = 1 byte.
I think it's not needed for the source code of the service (“Runtime_service.dpr”) and the interface part (“Yeti_syslog.dpr”) – to use UTF-8 string from the Delphi 2009/2010/XE/XE2.
And if you'll want to make 64-bit applications in the recent Delphi XE2 – I think it'll be no problem.
I decided to use ready and prooved source for this part. There is unit 'EventLog'. It uses the part of JEDI library (“JwaWin*”). Ok, I added this unit and the part of JEDI library (several uncommented *.inc, *.pas files). The URL from where they were taken – http://code.google.com/p/delphi-wmi-class-generator/source/browse/trunk/units/?r=30
The 'EventLog' unit has the detailed description, and I placed it here.
We can not to run the program under debugger on different OS, therefore for testing we should use some another way to see how the application work, and to know where it'll has errors.
File 'debug.txt' – being exists in the directory with the service will enable the service to write out the file 'yeti_debug#####.txt' in the appent mode where it'll log every points in/out into procedures to have a log. Where ##### is a timestamp when the program was started.