Skip to content

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

6 Commits
 
 
 
 
 
 

Repository files navigation

Polyglot.Logger

.NET bindings for Polyglot — a shared Go logging core with a C ABI. Same polyglot.yaml, JSON shape, and sinks as the Node and Python packages. Native libs ship in the NuGet package (Linux, Windows, macOS arm64); no Go/CGO required.

Current line: 0.3.x.

dotnet add package Polyglot.Logger
using Polyglot.Logger;

using var log = new Logger(new LoggerOptions { Service = "api", Stdout = true });
log.Info("hello", new Dictionary<string, object?> { ["user_id"] = 1 });

Prefer using so dispose always runs and sinks shut down cleanly. Side-by-side APIs: sdk.md.

Config file (optional)

Constructors load polyglot.yaml via POLYGLOT_CONFIG → cwd → parents (stop at .git). Options override file keys.

# polyglot.yaml (repo root)
service: billing-api
environment: prod
level: info
stdout: true
file:
  enabled: true
  path: app.log
using var log = new Logger(new LoggerOptions { Service = "billing-api" });

Full schema: configuration · zero-config.

Levels, fields, lifecycle

using Polyglot.Logger;

using var log = new Logger(new LoggerOptions
{
    Service = "billing-api",
    Environment = "prod",
    Level = "info",
    Stdout = true,
});

log.SetFields(new Dictionary<string, object?> { ["region"] = "us-east" });
using var req = log.With(new Dictionary<string, object?> { ["request_id"] = "r1" });
req.Info("invoice issued", new Dictionary<string, object?> { ["invoice_id"] = 99 });
req.LogSimple(Level.Error, "billing failed");

log.Flush();
  • Levels: TraceFatal (Fatal does not call Environment.Exit).
  • Prefer With(...) (or RequestLogging.ForRequest) for per-request context; avoid sharing SetFields across concurrent requests.
  • One instance is fine for concurrent Info / Flush / Stats / SetFields. Dispose the root logger to shut down sinks; disposing a child only frees the child handle.
  • On Windows, dispose before reading the active log file from the same process.

Native library

Published packages include platform natives under native/ / bin/ (and NuGet runtimes/). For a local monorepo build:

export POLYGLOT_LOGGER_LIB=$PWD/dist/logger.dll   # liblogger.so / liblogger.dylib

Intel Macs: arm64 is what ships today; set POLYGLOT_LOGGER_LIB for amd64 until CI covers it.

From source

git clone --recurse-submodules https://github.com/kishankumarhs/Polyglot.git
cd Polyglot && make build-native
dotnet build bindings/dotnet/Polyglot.Logger/Polyglot.Logger.csproj

Docs

Polyglot is for multi-language stacks that want one ops model — shared config and sinks without reimplementing them per language.

Repos: polyglot-csharp · core: Polyglot

MIT

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

Packages

Contributors

Languages