Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="AutoMapper" Version="13.0.1" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.1" />
<PackageReference Include="Serilog.Expressions" Version="4.0.0" />
<PackageReference Include="Serilog.Formatting.Compact" Version="2.0.0" />
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.5.0" />
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="8.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.2" />
Expand Down
19 changes: 19 additions & 0 deletions DotnetFoundation/DotnetFoundation.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
using DotnetFoundation.Services;
using Microsoft.AspNetCore.Mvc;
using Microsoft.OpenApi.Models;
using Serilog;
using Serilog.Templates;
using Swashbuckle.AspNetCore.Filters;
using System.Reflection;
using System.Text.Json.Serialization;
Expand Down Expand Up @@ -52,6 +54,21 @@
options.IncludeXmlComments(filePath);
});

// logging using serilog
Log.Logger = new LoggerConfiguration()
.WriteTo.File(
formatter: new ExpressionTemplate(
"{ {Timestamp: @t, Level: @l, TracebackId: @tr, RequestMethod, RequestPath, StatusCode, SourceContext, Data:{EventId: @i, RequestId}, Message: @m, Exception: @x} }\n\n"
),
path: "logs/log-.ndjson",
rollingInterval: RollingInterval.Day)
.WriteTo.Console(
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss zzz} [{Level:u3}] {Message:lj} <s:{SourceContext}>{NewLine}{Exception}\n")
.CreateLogger();

Log.Logger.Information("Logging has started");
builder.Host.UseSerilog();

// Adding HTTP Context
builder.Services.AddHttpContextAccessor();

Expand All @@ -74,6 +91,8 @@

app.UseHttpsRedirection();

app.UseSerilogRequestLogging();

app.UseAuthentication();

app.UseAuthorization();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@
"Microsoft.AspNetCore": "Warning"
}
}
}
}