change logger on program.cs
This commit is contained in:
@@ -15,6 +15,7 @@
|
|||||||
<PrivateAssets>all</PrivateAssets>
|
<PrivateAssets>all</PrivateAssets>
|
||||||
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
|
||||||
</PackageReference>
|
</PackageReference>
|
||||||
|
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="10.0.0" />
|
||||||
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.1" />
|
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="10.0.1" />
|
||||||
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
|
<PackageReference Include="SixLabors.ImageSharp" Version="3.1.12" />
|
||||||
<!--<PackageReference Include="System.Text.Encodings.Web" Version="10.0.0" />-->
|
<!--<PackageReference Include="System.Text.Encodings.Web" Version="10.0.0" />-->
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using Microsoft.AspNetCore.Http;
|
|||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
|
||||||
|
|
||||||
namespace GozareshgirProgramManager.Infrastructure.Services.FileManagement;
|
namespace GozareshgirProgramManager.Infrastructure.Services.FileManagement;
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
|
|||||||
@@ -380,23 +380,30 @@ builder.Services.AddParbad().ConfigureGateways(gateways =>
|
|||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
// فقط Serilog برای File استفاده میشه، کنسول از لاگر پیشفرض ASP.NET استفاده میکنه
|
if (builder.Environment.IsDevelopment())
|
||||||
builder.Host.UseSerilog((context, services, configuration) =>
|
|
||||||
{
|
{
|
||||||
var logConfig = configuration
|
builder.Host.UseSerilog((context, services, configuration) =>
|
||||||
.ReadFrom.Configuration(context.Configuration)
|
{
|
||||||
.ReadFrom.Services(services)
|
var logConfig = configuration
|
||||||
.Enrich.FromLogContext();
|
.ReadFrom.Configuration(context.Configuration)
|
||||||
|
.ReadFrom.Services(services)
|
||||||
|
.Enrich.FromLogContext();
|
||||||
|
|
||||||
|
|
||||||
logConfig.WriteTo.File(
|
logConfig.WriteTo.File(
|
||||||
path: Path.Combine(logDirectory, "gozareshgir_log.txt"),
|
path: Path.Combine(logDirectory, "gozareshgir_log.txt"),
|
||||||
rollingInterval: RollingInterval.Day,
|
rollingInterval: RollingInterval.Day,
|
||||||
retainedFileCountLimit: 30,
|
retainedFileCountLimit: 30,
|
||||||
shared: true,
|
shared: true,
|
||||||
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"
|
outputTemplate: "{Timestamp:yyyy-MM-dd HH:mm:ss} [{Level}] {Message}{NewLine}{Exception}"
|
||||||
);
|
);
|
||||||
}, writeToProviders: true); // این باعث میشه کنسول پیشفرض هم کار کنه
|
}, writeToProviders: true); // این باعث میشه کنسول پیشفرض هم کار کنه
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
builder.Host.UseSerilog();
|
||||||
|
}
|
||||||
|
|
||||||
Log.Information("SERILOG STARTED SUCCESSFULLY");
|
Log.Information("SERILOG STARTED SUCCESSFULLY");
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user