From e8b9fe0dc351bcd22986875042ca4ff7fe88f2c5 Mon Sep 17 00:00:00 2001 From: Bangara Raju Kottedi Date: Wed, 1 May 2024 00:45:22 +0530 Subject: [PATCH] serilog configuration changed based on environments --- PortBlog.API/Program.cs | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/PortBlog.API/Program.cs b/PortBlog.API/Program.cs index cce56f9..9732122 100644 --- a/PortBlog.API/Program.cs +++ b/PortBlog.API/Program.cs @@ -9,13 +9,25 @@ using PortBlog.API.Middleware; using Serilog; using System.Reflection; -Log.Logger = new LoggerConfiguration() + + +var builder = WebApplication.CreateBuilder(args); + +if (builder.Environment.IsDevelopment()) +{ + Log.Logger = new LoggerConfiguration() .MinimumLevel.Debug() .WriteTo.Console() .WriteTo.File("logs/portblog.txt", rollingInterval: RollingInterval.Day) .CreateLogger(); - -var builder = WebApplication.CreateBuilder(args); +} +else +{ + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Information() + .WriteTo.File("logs/portblog.txt", rollingInterval: RollingInterval.Day) + .CreateLogger(); +} var urls = builder.Configuration.GetSection("Urls");