Firemonkey IFMXLoggingService Windows Event Log Location

被刻印的时光 ゝ 提交于 2019-12-11 13:15:01

问题


I am looking at the FMX built in logging support via the Log class which uses the IFMXLoggingService to write events. I have found info for the log file location in iOS and Android but unable to find anything on Windows (8.1).

Does anyone know which specific log file this service writes to? and is this able to be changed in code or otherwise?

Thanks


回答1:


If you look at the sources you will find the implementation at FMX.Platform.Win.TPlatformWin.Log:

procedure TPlatformWin.Log(const Fmt: string; const Params: array of const);
begin
  OutputDebugString(PChar(Format(Fmt, Params)));
end;

OutputDebugString() does not send messages to any log file at all. It logs to the debugger's built-in event log, when the app is running inside the debugger. When the app is running outside of the debugger, third-party tools like SysInternal DebugView can capture these messages.

If you want to use a custom logger, write a class that implements the IFMXLoggingService interface and register it with FMX at runtime:

type
  TMyLoggingService = class(TInterfacedObject, IFMXLoggingService)
  public
    procedure Log(const Format: string; const Params: array of const);
  end;

procedure TMyLoggingService.Log(const Format: string; const Params: array of const);
begin
  // do whatever you want...
end;

var
  MyLoggingService : IFMXLoggingService;
begin
  MyLoggingService := TMyLoggingService.Create;

  // if a service is already registered, remove it first
  if TPlatformServices.Current.SupportsPlatformService( IFMXLoggingService ) then
    TPlatformServices.Current.RemovePlatformService( IFMXLoggingService );

  // now register my service
  TPlatformServices.Current.AddPlatformService( IFMXLoggingService, MyLoggingService );
end;

This is mentioned in Embarcadero's documentation:

You can use TPlatformServices.AddPlatformService and TPlatformServices.RemovePlatformService to register and unregister platform services, respectively.

For example, you can unregister one of the built-in platform services and replace it with a new implementation of the platform service that is tailored to fit your needs.



来源:https://stackoverflow.com/questions/32631001/firemonkey-ifmxloggingservice-windows-event-log-location

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!