Skip to content

Logging and Diagnostics

Mike Christensen edited this page Aug 28, 2026 · 2 revisions

Logging and diagnostics

KitchenPC Core and DB use log4net internally. Applications configure appenders and levels; the libraries do not choose log destinations.

Basic log4net configuration

Add a log4net.config file:

<?xml version="1.0" encoding="utf-8" ?>
<log4net>
  <appender name="Console" type="log4net.Appender.ConsoleAppender">
    <layout type="log4net.Layout.PatternLayout">
      <conversionPattern value="[%level] %logger - %message%newline" />
    </layout>
  </appender>
  <root>
    <level value="WARN" />
    <appender-ref ref="Console" />
  </root>
  <logger name="KitchenPC.Core.NLP.Parser">
    <level value="INFO" />
  </logger>
</log4net>

Initialize log4net according to the hosting model before context startup. In modern .NET, one option is:

log4net.Config.XmlConfigurator.Configure(
   new FileInfo("log4net.config"));

Database import/export, NHibernate, Npgsql, and the modeler have their own logger categories. Start at WARN, temporarily raise only the category being diagnosed, and avoid logging connection strings or user-entered recipe data in production.

NLP trace

Ordinary parser logging summarizes activity. NLP tracing records grammar templates, synonym resolution, form pairing, anomaly fallbacks, and failure decisions:

using KitchenPC.Core.NLP;

NlpTracer.SetTracer(new DefaultTracer());
var result = context.ParseIngredientUsage("a dozen bananas");

For another destination, implement ITracer and pass it to SetTracer. The interface receives trace level, format string, and arguments. Because tracing is global and extremely verbose, configure it once and use it only for focused diagnostics.

What to capture

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.

Diagnosing a parse

  1. Preserve the original input and Result.Status.
  2. Enable an NLP tracer in a safe development environment.
  3. Check ingredient and synonym presence.
  4. Check the default form pairing for the parsed unit type.
  5. Check form/unit compatibility and custom-unit mappings.
  6. Improve source metadata instead of hard-coding UI-only exceptions when the rule is generally valid.

Clone this wiki locally