Skip to content

Commit

Permalink
feat: add serilog file logging
Browse files Browse the repository at this point in the history
  • Loading branch information
valchetski committed Sep 2, 2024
1 parent 2d9d2f9 commit 66a8d39
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/Tgvs/Program.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Microsoft.Extensions.Options;
using Serilog;
using Telegram.Bot;
using Telegram.Bot.Polling;
using Tgvs;
Expand All @@ -15,6 +16,9 @@
.AddMemoryCache()
.AddApplicationInsightsTelemetry();

builder.Host.UseSerilog((ctx, lc) => lc
.ReadFrom.Configuration(ctx.Configuration));

var telegramSection = builder.Configuration.GetSection("Telegram");
builder.Services.Configure<TelegramBotConfig>(telegramSection);
builder.Services.AddHttpClient("telegram_bot_client")
Expand Down
2 changes: 2 additions & 0 deletions src/Tgvs/Tgvs.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.6" />
<PackageReference Include="Serilog.AspNetCore" Version="8.0.2" />
<PackageReference Include="Serilog.Sinks.File" Version="6.0.0" />
<PackageReference Include="Telegram.Bot" Version="19.0.0" />
</ItemGroup>

Expand Down
14 changes: 14 additions & 0 deletions src/Tgvs/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,20 @@
"Microsoft.AspNetCore": "Warning"
}
},
"Serilog": {
"MinimumLevel": {
"Default": "Warning"
},
"WriteTo": [
{
"Name": "File",
"Args": {
"path": "logs/tgvs.log",
"rollingInterval": "Day"
}
}
]
},
"AllowedHosts": "*",
"ConnectionStrings": {
"Stickers": "set-in-secrets"
Expand Down

0 comments on commit 66a8d39

Please sign in to comment.