initial commit
This commit is contained in:
33
Program.cs
Normal file
33
Program.cs
Normal file
@@ -0,0 +1,33 @@
|
||||
using OpenTelemetry.Logs;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var useOtlpExporter = !string.IsNullOrWhiteSpace(builder.Configuration["OTEL_EXPORTER_OTLP_ENDPOINT"]);
|
||||
|
||||
builder.Logging.AddOpenTelemetry(logging =>
|
||||
{
|
||||
logging.IncludeFormattedMessage = true;
|
||||
logging.IncludeScopes = true;
|
||||
|
||||
if (useOtlpExporter)
|
||||
{
|
||||
logging.AddOtlpExporter();
|
||||
}
|
||||
else
|
||||
{
|
||||
Console.WriteLine("OTEL_EXPORTER_OTLP_ENDPOINT is not set. Skipping OTLP exporter configuration.");
|
||||
}
|
||||
});
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
app.MapGet("/", () => "Hello World!");
|
||||
|
||||
app.MapGet("/log", (ILogger<Program> logger) =>
|
||||
{
|
||||
if (logger.IsEnabled(LogLevel.Information))
|
||||
logger.LogInformation("Logging a message at {time:HH:mm:ss} on {machine}", DateTime.Now, Environment.MachineName);
|
||||
return Results.Ok();
|
||||
});
|
||||
|
||||
app.Run();
|
||||
Reference in New Issue
Block a user