Skip to content

Commit

Permalink
feat: add and configure Serilog
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosPavajeau committed Oct 4, 2021
1 parent fe168e9 commit b0cd5eb
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/Armory.Api/Armory.Api.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="5.0.1"/>
<PackageReference Include="Serilog.AspNetCore" Version="4.1.0"/>
<PackageReference Include="Serilog.Settings.Configuration" Version="3.2.0"/>
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.2.2"/>
</ItemGroup>

Expand Down
14 changes: 14 additions & 0 deletions src/Armory.Api/Program.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
using Armory.Api.Extensions;
using Armory.Shared.Infrastructure.Persistence.EntityFramework;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Hosting;
using Serilog;

namespace Armory.Api
{
public static class Program
{
public static void Main(string[] args)
{
ConfigureLogger();
CreateHostBuilder(args).Build().MigrateDatabase<ArmoryDbContext>().Run();
}

private static void ConfigureLogger()
{
var configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", false, true).Build();

Log.Logger = new LoggerConfiguration()
.ReadFrom.Configuration(configuration)
.CreateLogger();
}

public static IHostBuilder CreateHostBuilder(string[] args)
{
return Host.CreateDefaultBuilder(args)
.UseSerilog()
.ConfigureWebHostDefaults(webBuilder => { webBuilder.UseStartup<Startup>(); });
}
}
Expand Down
15 changes: 14 additions & 1 deletion src/Armory.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,18 @@
"SecretKey": {
"Key": "SECRET_AND_SECURE_KEY"
},
"AllowedUrls": ["http://localhost:3000/"]
"Serilog": {
"MinimumLevel": "Information",
"WriteTo": [
{
"Name": "Console"
}
],
"Properties": {
"ApplicationName": "AspNetTest"
}
},
"AllowedUrls": [
"http://localhost:3000"
]
}

0 comments on commit b0cd5eb

Please sign in to comment.