Root > Advanced topics > System logging setup > Using dynamic content with System Log

Using dynamic content with System Log

Previous pageReturn to chapter overviewNext page   

You can write template text when you define your events. This template can include qualificators like %1, %2, etc. Qualificator defines variable part of event. Each logged event will contain reference to template's text, so template's text is not stored into log itself (thus, saving storage space). But any dynamic content for qualificators will be stored inside log. When you're viewing log - dynamic content will be inserted into qualificator's positions and form a full error message.

 

EurekaLog defines two qualificator by default: exception message and full path to bug report file.

 

You can alter default behavior to store arbitrary dynamic data. You can do this by altering send class. First, you need to declare your own send class which will contain your customizations and register it within EurekaLog:

 

unit CustomizedSystemLog;
 
interface
 
implementation
 
uses
  Classes,
  EDialog,
  EDialogService;
 
type
  TEventLogDialog = class(EDialogService.TEventLogDialog)
  end;
 
initialization
  RegisterDialogClassFirst(TEventLogDialog);
end.

 

Next, you can alter behavior as you like. For example, default TEventLogDialog class has virtual method FillData with default implementation as follows:

 

procedure TEventLogDialog.FillData(const AData: TStrings);
begin
  AData.Add(ExceptionInfo.ExceptionMessage);
  AData.Add(LogFileName);
end;

 

which you can override to define your own dynamic content. You can use ExceptionInfo property of dialog class to get access to different properties of logged exception in question. You can also use BugReport property to gain access to bug report content.

 

The following example defines 4 custom dynamic pieces: %1 for exception message, %2 for exception type, %3 for compact call stack, %4 for BugID.

 

unit CustomizedSystemLog;
 
interface
 
implementation
 
uses
  SysUtils,
  Classes,
  ECallStack,
  EDialog,
  EDialogService;
 
type
  TEventLogDialog = class(EDialogService.TEventLogDialog)
  protected
    procedure FillData(const AData: TStrings); override;
  end;
 
{ TEventLogDialog }
 
procedure TEventLogDialog.FillData(const AData: TStrings);
var
  Formatter: TCompactStackFormatter;
  CallStack: String;
begin
  Formatter := TCompactStackFormatter.Create;
  try
    CallStack := CallStackToString(ExceptionInfo.CallStack, '', Formatter);
  finally
    FreeAndNil(Formatter);
  end;
 
  // %1
  AData.Add(ExceptionInfo.ExceptionMessage);
 
  // %2
  AData.Add(ExceptionInfo.ExceptionClass);
 
  // %3
  AData.Add(CallStack);
 
  // %4
  AData.Add(ExceptionInfo.BugIDStr);
end;
 
initialization
  RegisterDialogClassFirst(TEventLogDialog);
end.

 

You can use the following .mc file for this example:

 

MessageIdTypedef=DWORD

SeverityNames=(Success=0x0:STATUS_SEVERITY_SUCCESS

              Informational=0x1:STATUS_SEVERITY_INFORMATIONAL

              Warning=0x2:STATUS_SEVERITY_WARNING

              Error=0x3:STATUS_SEVERITY_ERROR

             )

FacilityNames=(System=0x0:FACILITY_SYSTEM

              Runtime=0x2:FACILITY_RUNTIME

              Stubs=0x3:FACILITY_STUBS

              Io=0x4:FACILITY_IO_ERROR_CODE

             )

LanguageNames=(English=0x409:MSG00409)

MessageId=0x1

Severity=Error

Facility=Runtime

SymbolicName=mcEurekaLogErrorMessage

Language=English

There was an exception #%4 of type %2 with message:%n%1%nCall stack:%n%3

.

 

The result will look like this:

 

 

An event with the 4 custom qualificators

 

Note: you can look at NT Service Application demo which is shipped with EurekaLog.

 

 

See also:




Send feedback... Build date: 2024-09-30
Last edited: 2023-03-07
PRIVACY STATEMENT
The documentation team uses the feedback submitted to improve the EurekaLog documentation. We do not use your e-mail address for any other purpose. We will remove your e-mail address from our system after the issue you are reporting has been resolved. While we are working to resolve this issue, we may send you an e-mail message to request more information about your feedback. After the issues have been addressed, we may send you an email message to let you know that your feedback has been addressed.


Permanent link to this article: https://www.eurekalog.com/help/eurekalog/system_log_dynamic_content.php