Class ConsoleJsonLogExporter
Exports log records to the console where each record will be written as a line of JSON text to standard output and/or standard error when configured.
This is suitable for production environments like Kubernetes, Docker, etc. where logs are captured from the program output.
Namespace: Neon.Diagnostics
Assembly: Neon.Common.dll
Syntax
public class ConsoleJsonLogExporter : BaseExporter<LogRecord>
Remarks
IMPORTANT: To enable the inclusion of log tags in the output JSON, you must
set OpenTelemetryLoggerOptions.ParseStateValues=true
when
configuring your OpenTelemetry options. This is is false
by default.
var loggerFactory = LoggerFactory.Create(
builder =>
{
builder.AddOpenTelemetry(
options =>
{
options.ParseStateValues = true; // <--- SET THIS TO TRUE
options.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService(serviceName: ServiceName, serviceVersion: ServiceVersion));
options.AddLogAsTraceProcessor(options => options.LogLevel = LogLevel.Warning);
options.AddConsoleJsonExporter();
});
});</code></pre>
Constructors
ConsoleJsonLogExporter(ConsoleJsonLogExporterOptions)
Constructs a log exporter that writes log records to standard output and/or standard error as single line JSON objects.
Declaration
public ConsoleJsonLogExporter(ConsoleJsonLogExporterOptions options = null)
Parameters
Type | Name | Description |
---|---|---|
ConsoleJsonLogExporterOptions | options | Optionally specifies the exporter options. |
Methods
Export(in Batch<LogRecord>)
Declaration
public override ExportResult Export(in Batch<LogRecord> batch)
Parameters
Type | Name | Description |
---|---|---|
Batch<LogRecord> | batch |
Returns
Type | Description |
---|---|
ExportResult |