delphimvcframework/LoggerPro.WindowsEventLogAppender.pas
Daniele Teti 690031594c Squashed 'lib/loggerpro/' changes from 100b0ce0..0d39e1d1
0d39e1d1 New LogLevel: FATAL
5248b9de Improved fileformatname check
657a539d https://github.com/danieleteti/loggerpro/issues/79
67729f57 https://github.com/danieleteti/loggerpro/issues/72
f05a91a6 https://github.com/danieleteti/loggerpro/issues/73
3c805c0f Merge pull request #71 from luebbe/master
3a790459 Fixes #70 Add test to expose #70

git-subtree-dir: lib/loggerpro
git-subtree-split: 0d39e1d1549d42fa20b71503eed944043771b7bb
2023-10-18 16:25:23 +02:00

62 lines
1.4 KiB
ObjectPascal

unit LoggerPro.WindowsEventLogAppender;
{ <@abstract(The unit to include if you want to use @link(TLoggerProWindowsEventLogAppender))
@author(David Cornelius) }
{$IFNDEF MSWINDOWS}
{$MESSAGE FATAL 'This unit only works with Windows'}
{$ENDIF}
interface
uses
Vcl.SvcMgr,
LoggerPro;
type
{ @abstract(This appender is for logging from Windows Services to the Windows Event Log) }
TLoggerProWindowsEventLogAppender = class(TLoggerProAppenderBase)
private
FService: TService;
public
constructor Create(AService: TService); reintroduce;
procedure Setup; override;
procedure TearDown; override;
procedure WriteLog(const aLogItem: TLogItem); override;
end;
implementation
uses
Winapi.Windows;
constructor TLoggerProWindowsEventLogAppender.Create(AService: TService);
begin
inherited Create;
FService := AService;
end;
procedure TLoggerProWindowsEventLogAppender.Setup;
begin
// do nothing
end;
procedure TLoggerProWindowsEventLogAppender.TearDown;
begin
// do nothing
end;
procedure TLoggerProWindowsEventLogAppender.WriteLog(const aLogItem: TLogItem);
begin
case aLogItem.LogType of
TLogType.Debug,
TLogType.Info:
FService.LogMessage(aLogItem.LogMessage, EVENTLOG_INFORMATION_TYPE);
TLogType.Warning:
FService.LogMessage(aLogItem.LogMessage, EVENTLOG_WARNING_TYPE);
TLogType.Error, TLogType.Fatal:
FService.LogMessage(aLogItem.LogMessage, EVENTLOG_ERROR_TYPE);
end;
end;
end.