Class LogProvider
- Namespace
- Quartz.Diagnostics
- Assembly
- Quartz.dll
The logger factory Quartz logs to from the places that cannot be handed one.
public static class LogProvider
- Inheritance
-
LogProvider
- Inherited Members
Remarks
This is ambient, mutable, process-wide state, and it stays that way on purpose. Everything the scheduler is made of is built by a container and is injected an ILogger the ordinary way — the scheduler and its loop, the job store and everything it owns, the thread pool, the job factory, the type loader, the instance id generator — so a hosted application gets all of that without touching this slot at all.
What is left over cannot be injected anything, and this is the whole of it: the broadcast listeners
and JobChainingJobListener, which a caller constructs and hands over
already built; CronTriggerImpl, which is a trigger and may have
been deserialized out of a job store; the static helpers TimeZones,
MisfireInstructionNames, FileUtil and QuartzEnvironment; and the
types in the satellite packages a caller constructs directly, such as the jobs in
Quartz.Jobs. A type cannot be handed a logger by a container it never meets, so those sites
read this instead of going unlogged.
It is deliberately not seeded from the container either, which would otherwise be the obvious convenience. This slot outlives any one container: a process that builds a host, disposes it and builds another — every integration test suite, and every application that reloads configuration — would be left holding a disposed ILoggerFactory, and the next CreateLogger<T>() would throw ObjectDisposedException from somewhere unrelated to logging. Whoever sets this has to own the lifetime of what they set, which is a decision only the application can make.
A logger is usually resolved once, when the type that logs is constructed, so setting the factory after a scheduler has been running affects only what is created from then on.
Methods
CreateLogger(string)
A logger under the given category, from whatever SetLogProvider(ILoggerFactory) was handed — or one that logs nothing, when it was handed nothing.
public static ILogger CreateLogger(string category)
Parameters
categorystringThe category to log under.
Returns
CreateLogger<T>()
A logger categorised by T, from whatever
SetLogProvider(ILoggerFactory) was handed — or one that logs nothing, when it was handed nothing.
public static ILogger<T> CreateLogger<T>()
Returns
- ILogger<T>
Type Parameters
TThe type the category is named for.
SetLogProvider(ILoggerFactory)
Sets the logger factory Quartz logs to where no logger can be injected. Until this is called, those sites log to NullLogger.
public static void SetLogProvider(ILoggerFactory loggerFactory)
Parameters
loggerFactoryILoggerFactoryThe logger factory.
Remarks
An application on AddQuartz does not need this: the scheduler and everything it is built
from log through the container's ILoggerFactory. What this reaches is the list of
leftovers above — a listener you constructed, a trigger, a static helper, a job from
Quartz.Jobs.
A standalone QuartzSchedulerBuilder is the exception, and calling this is how it
is meant to be configured: the container it builds for itself has no logging providers of its
own, so it forwards to this. Registering a provider on its Services instead takes that
over.
Pass a factory that lives at least as long as the schedulers in the process. Handing over a factory owned by a host and then disposing that host leaves this pointing at a disposed object.