-
Notifications
You must be signed in to change notification settings - Fork 32
Logging and Diagnostics
KitchenPC Core and DB use Microsoft.Extensions.Logging, the standard logging abstraction for
modern .NET. The libraries select categories and levels but never choose a destination. Logging is
optional; contexts use NullLoggerFactory unless an application supplies a factory.
Add a provider package such as Microsoft.Extensions.Logging.Console, create a factory for the
application lifetime, and pass it to the context builder before initialization:
using KitchenPC.Core;
using KitchenPC.Core.Context;
using Microsoft.Extensions.Logging;
using var loggerFactory = LoggerFactory.Create(logging =>
{
logging.SetMinimumLevel(LogLevel.Warning);
logging.AddSimpleConsole(options => options.SingleLine = true);
logging.AddFilter("KitchenPC", LogLevel.Information);
});
var context = StaticContext.Configure
.DataDirectory(dataDirectory)
.Logging(loggerFactory)
.Identity(() => AuthIdentity.Anonymous)
.Create();
context.Initialize();DBContext.Configure.Logging uses the same pattern. Its logger factory flows to the database
adapter, importer, exporter, parser, and modeler. DatabaseAdapter.Configure.Logging is also
available when an adapter is used directly for provisioning before it belongs to a context.
ASP.NET Core already configures Microsoft logging. If context-initialization logs are required,
create or retain an ILoggerFactory for the application lifetime and pass it through
.Logging(loggerFactory) while building the root context. Send output to the providers appropriate
for the host—console, OpenTelemetry, Application Insights, or another provider—without changing
KitchenPC.
Useful KitchenPC categories include:
-
KitchenPC.Core.NLP.Parserfor parsing and synonym diagnostics; -
KitchenPC.Core.Modeler.DBSnapshotandKitchenPC.Core.Modeler.ModelingSessionfor modeler timing; -
KitchenPC.DB.DatabaseImporterandKitchenPC.DB.DatabaseExporterfor provisioning counts.
NHibernate and Npgsql maintain their own categories. Start at Warning, temporarily raise only the
category being diagnosed, and never log connection strings or sensitive user-entered recipe data.
Context initialization connects the built-in NLP trace to the configured logger factory. Existing applications can also choose a tracer explicitly:
using KitchenPC.Core.NLP;
NlpTracer.SetTracer(new DefaultTracer(loggerFactory));
var result = context.ParseIngredientUsage("a dozen bananas");For another destination or trace representation, implement ITracer and pass it to SetTracer.
The interface receives a trace level, composite-format string, and arguments. NLP tracing is global
and can be extremely verbose, so configure it once and use detailed output only for focused
diagnostics.
Useful operational signals include:
- context initialization duration and selected capabilities;
- recipe search duration, result count, and sanitized filter summary;
- NLP status counts without raw personal data;
- provisioning/import phase and record counts;
- missing-capability and incompatible-amount exceptions;
- database connectivity and timeout failures.
- Preserve the original input and
Result.Statusin a safe development environment. - Enable the
KitchenPC.Core.NLP.Parsercategory or install a focusedITracer. - Check ingredient and synonym presence.
- Check the default form pairing for the parsed unit type.
- Check form/unit compatibility and custom-unit mappings.
- Improve source metadata instead of hard-coding UI-only exceptions when the rule is generally valid.
KitchenPC is MIT licensed. Runnable applications live in KitchenPC/Samples.