Starts watching. The caller owns the result and should dispose it when the reason for watching goes away.
Watchers still running when the application stops are disposed with it, so
a forgotten one leaks for the session rather than past it.
Listener callbacks are not wrapped in an OperationContext; use the
declarative module watcher when operation logging/error classification is
required.
Watching a path chosen while the extension is running.
Distinct from
module.fileWatchers.add, which declares the globs an extension always watches — those are bound at activation, run their handler in an operation, and are torn down with the module. This is the other case: the user picks a log file or types a glob, and the watcher exists only for as long as that choice does. Declaring it is impossible, because the pattern is not known until the user says so.Prefer the declaration whenever the pattern is known up front — it comes with the operation context, the diagnostics and the ownership for free.
Example