Добавил логирование в телеграм
This commit is contained in:
@@ -3,13 +3,17 @@ using Quartz;
|
||||
using SfeduSchedule;
|
||||
using SfeduSchedule.Jobs;
|
||||
using SfeduSchedule.Services;
|
||||
using X.Extensions.Logging.Telegram.Extensions;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
var configuration = builder.Configuration;
|
||||
string? preinstsalledJwtToken = configuration["TOKEN"];
|
||||
string? preinstalledJwtToken = configuration["TOKEN"];
|
||||
string? tgChatId = configuration["TG_CHAT_ID"];
|
||||
string? tgToken = configuration["TG_TOKEN"];
|
||||
string updateJwtCron = configuration["UPDATE_JWT_CRON"] ?? "0 4 * ? * *";
|
||||
|
||||
|
||||
// создать папку data если не существует
|
||||
var dataDirectory = Path.Combine(AppContext.BaseDirectory, "data");
|
||||
if (!Directory.Exists(dataDirectory))
|
||||
@@ -18,7 +22,23 @@ if (!Directory.Exists(dataDirectory))
|
||||
}
|
||||
GlobalVariables.JwtFilePath = Path.Combine(dataDirectory, "jwt.txt");
|
||||
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
builder.Logging.ClearProviders();
|
||||
builder.Logging.AddConsole();
|
||||
if (!string.IsNullOrEmpty(tgChatId) && !string.IsNullOrEmpty(tgToken))
|
||||
builder.Logging.AddTelegram(options =>
|
||||
{
|
||||
options.ChatId = tgChatId;
|
||||
options.AccessToken = tgToken;
|
||||
options.FormatterConfiguration.UseEmoji = true;
|
||||
options.FormatterConfiguration.ReadableApplicationName = "Sfedu Schedule";
|
||||
options.LogLevel = new Dictionary<string, LogLevel>
|
||||
{
|
||||
{ "Default", LogLevel.Error },
|
||||
{ "SfeduSchedule.Jobs.UpdateJwtJob", LogLevel.Information }
|
||||
};
|
||||
});
|
||||
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddHttpClient<ModeusService>();
|
||||
|
||||
@@ -26,7 +46,7 @@ builder.Services.AddMicrosoftIdentityWebAppAuthentication(builder.Configuration)
|
||||
|
||||
var jobKey = new JobKey("UpdateJWTJob");
|
||||
|
||||
if (string.IsNullOrEmpty(preinstsalledJwtToken))
|
||||
if (string.IsNullOrEmpty(preinstalledJwtToken))
|
||||
{
|
||||
builder.Services.AddQuartz(q =>
|
||||
{
|
||||
@@ -56,7 +76,7 @@ app.UseForwardedHeaders();
|
||||
|
||||
var logger = app.Services.GetRequiredService<ILogger<Program>>();
|
||||
|
||||
if (string.IsNullOrEmpty(preinstsalledJwtToken))
|
||||
if (string.IsNullOrEmpty(preinstalledJwtToken))
|
||||
{
|
||||
var schedulerFactory = app.Services.GetRequiredService<ISchedulerFactory>();
|
||||
var scheduler = await schedulerFactory.GetScheduler();
|
||||
@@ -106,7 +126,7 @@ app.UseStaticFiles();
|
||||
app.MapGet("/", async context =>
|
||||
{
|
||||
context.Response.ContentType = "text/html; charset=utf-8";
|
||||
await context.Response.SendFileAsync(Path.Combine(app.Environment.WebRootPath ?? "wwwroot", "index.html"));
|
||||
await context.Response.SendFileAsync(Path.Combine(app.Environment.WebRootPath, "index.html"));
|
||||
});
|
||||
|
||||
app.MapControllers();
|
||||
|
@@ -15,6 +15,7 @@
|
||||
<PackageReference Include="Microsoft.Playwright" Version="1.55.0" />
|
||||
<PackageReference Include="Quartz.AspNetCore" Version="3.15.0" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="9.0.4" />
|
||||
<PackageReference Include="X.Extensions.Logging.Telegram" Version="2.0.2" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
@@ -12,7 +12,9 @@ services:
|
||||
- AzureAd:CallbackPath=/signin-oidc
|
||||
- MS_USERNAME=${MS_USERNAME}
|
||||
- MS_PASSWORD=${MS_PASSWORD}
|
||||
# - TOKEN=
|
||||
- TG_CHAT_ID=${TG_CHAT_ID}
|
||||
- TG_TOKEN=${TG_TOKEN}
|
||||
# - TOKEN=${TOKEN}
|
||||
volumes:
|
||||
- data:/app/data
|
||||
restart: always
|
||||
|
@@ -10,9 +10,11 @@ services:
|
||||
- AzureAd:ClientSecret=
|
||||
- AzureAd:Domain=sfedu.onmicrosoft.com
|
||||
- AzureAd:CallbackPath=/signin-oidc
|
||||
- MS_USERNAME=
|
||||
- MS_PASSWORD=
|
||||
# - TOKEN=
|
||||
- MS_USERNAME=${MS_USERNAME}
|
||||
- MS_PASSWORD=${MS_PASSWORD}
|
||||
- TG_CHAT_ID=${TG_CHAT_ID}
|
||||
- TG_TOKEN=${TG_TOKEN}
|
||||
# - TOKEN=${TOKEN}
|
||||
volumes:
|
||||
- ./data:/app/data
|
||||
restart: unless-stopped
|
||||
|
Reference in New Issue
Block a user