<PackageReference Include="NLog" Version="6.2.0" />

NLog.Targets.FileLifecycleHooks

public abstract class FileLifecycleHooks
Enables hooking into file and FileTarget lifecycle events. Hooks are invoked synchronously and therefore may affect application responsiveness if they perform long-running operations.
protected FileLifecycleHooks()

public virtual void OnFileClosed(string filePath)

Called after a log file has been closed by the FileTarget.

public virtual void OnFileDeleting(string filePath)

Called immediately before a log file is deleted by the FileTarget.

public virtual Stream OnFileOpened(string filePath, Stream underlyingStream)

Initializes or wraps the stream opened for a log file. This can be used to write file headers, or wrap the stream in another stream that adds buffering, compression, encryption, etc.

public virtual void OnTargetClose(FileTarget target)

Called when the FileTarget is being closed.

public virtual void OnTargetInitialize(FileTarget target)

Called when the FileTarget is initialized.