I am using .Net 6 Web Api application using C# and wanted to write logs only to console if ASPNETCORE_ENVIRONMENT = Development
and for non-dev wanted to write logs to Azure Blob Storage.
Question 1. How to use app builder
before it's created for code if (app.Environment.IsDevelopment())
? or I have to use Environment.GetEnvironmentVariable
?
Question 2. can this be achieved without if/else
block and within single line I can change the write context?
public static void Main(string[] args)
{
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
if (app.Environment.IsDevelopment())
{
builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.Console());
}
else
{
builder.Host.UseSerilog((ctx, lc) => lc
.WriteTo.AzureBlobStorage());
}