Firemonkey IFMXLoggingService Windows 事件日志位置
Firemonkey IFMXLoggingService Windows Event Log Location
我正在通过使用 IFMXLoggingService 写入事件的日志 class 查看 FMX 内置的日志记录支持。我在 iOS 和 Android 中找到了日志文件位置的信息,但在 Windows (8.1) 中找不到任何信息。
有谁知道这个服务写入了哪个特定的日志文件?这可以通过代码或其他方式更改吗?
谢谢
如果您查看源代码,您会在 FMX.Platform.Win.TPlatformWin.Log
:
找到实现
procedure TPlatformWin.Log(const Fmt: string; const Params: array of const);
begin
OutputDebugString(PChar(Format(Fmt, Params)));
end;
OutputDebugString()
根本不向任何日志文件发送消息。当应用程序在调试器中 运行 时,它会记录到调试器的内置事件日志中。当应用 运行 在调试器之外时,SysInternal DebugView 等第三方工具可以捕获这些消息。
如果您想使用自定义记录器,请编写一个实现 IFMXLoggingService
接口的 class 并在运行时向 FMX 注册它:
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;
这个在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.
我正在通过使用 IFMXLoggingService 写入事件的日志 class 查看 FMX 内置的日志记录支持。我在 iOS 和 Android 中找到了日志文件位置的信息,但在 Windows (8.1) 中找不到任何信息。
有谁知道这个服务写入了哪个特定的日志文件?这可以通过代码或其他方式更改吗?
谢谢
如果您查看源代码,您会在 FMX.Platform.Win.TPlatformWin.Log
:
procedure TPlatformWin.Log(const Fmt: string; const Params: array of const);
begin
OutputDebugString(PChar(Format(Fmt, Params)));
end;
OutputDebugString()
根本不向任何日志文件发送消息。当应用程序在调试器中 运行 时,它会记录到调试器的内置事件日志中。当应用 运行 在调试器之外时,SysInternal DebugView 等第三方工具可以捕获这些消息。
如果您想使用自定义记录器,请编写一个实现 IFMXLoggingService
接口的 class 并在运行时向 FMX 注册它:
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;
这个在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.