Különböző logok, különböző file-ba
This commit is contained in:
@@ -11,13 +11,43 @@ using WorkFlowCheck.DL.Seed;
|
||||
using WorkFlowCheck.Common.RequestContext;
|
||||
using WorkFlowCheck.API.RequestContext;
|
||||
using WorkFlowCheck.API.Middleware;
|
||||
using Serilog.Filters;
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
string baseLogPath = Path.Combine(Directory.GetCurrentDirectory(), "Logs");
|
||||
if (!Directory.Exists(baseLogPath))
|
||||
Directory.CreateDirectory(baseLogPath);
|
||||
|
||||
string auditLogPath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", "AuditFlow");
|
||||
if (!Directory.Exists(auditLogPath))
|
||||
Directory.CreateDirectory(auditLogPath);
|
||||
|
||||
string businessLogPath = Path.Combine(Directory.GetCurrentDirectory(), "Logs", "BusinessFlow");
|
||||
if (!Directory.Exists(businessLogPath))
|
||||
Directory.CreateDirectory(businessLogPath);
|
||||
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.ReadFrom.Configuration(builder.Configuration)
|
||||
.ReadFrom.Configuration(builder.Configuration) // Konfiguráció betöltése
|
||||
.WriteTo.Console()
|
||||
.WriteTo.File("logs/log-.log", rollingInterval: RollingInterval.Day)
|
||||
.WriteTo.Logger(lc => lc
|
||||
.Filter.ByIncludingOnly(Matching.WithProperty("TAG", "AuditFlow"))
|
||||
.WriteTo.File("Logs/AuditFlow/au-.log", rollingInterval: RollingInterval.Day)
|
||||
)
|
||||
.WriteTo.Logger(lc => lc
|
||||
.Filter.ByIncludingOnly(Matching.WithProperty("TAG", "BusinessFlow"))
|
||||
.WriteTo.File("Logs/BusinessFlow/bs-.log", rollingInterval: RollingInterval.Day)
|
||||
)
|
||||
.CreateLogger();
|
||||
|
||||
|
||||
//------------------------------------------------------------------------------------------------------------------
|
||||
|
||||
|
||||
Log.ForContext("TAG", "BusinessFlow").Information("API indítása...");
|
||||
|
||||
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
||||
builder.Services.AddMemoryCache();
|
||||
builder.Services.AddHttpContextAccessor();
|
||||
@@ -141,5 +171,7 @@ app.UseMiddleware<JwtMiddleware>();
|
||||
app.MapControllers();
|
||||
app.UseAuthorization();
|
||||
app.UseCors();
|
||||
|
||||
Log.ForContext("TAG", "BusinessFlow").Information("API fut.");
|
||||
app.Run();
|
||||
|
||||
|
||||
@@ -42,14 +42,14 @@
|
||||
</None>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="logs\" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Content Update="appsettings.Development.json">
|
||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||
</Content>
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<Folder Include="Logs\BusinessFlow\" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
||||
@@ -24,11 +24,44 @@
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "logs/log-.log",
|
||||
"path": "Logs/log-.log",
|
||||
"rollingInterval": "Day"
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Logger",
|
||||
"Args": {
|
||||
"filter": "Equals(TAG, 'AuditFlow')",
|
||||
"writeTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/AuditFlow/log-.txt",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
},
|
||||
{
|
||||
"Name": "Logger",
|
||||
"Args": {
|
||||
"filter": "Equals(TAG, 'BusinessFlow')",
|
||||
"writeTo": [
|
||||
{
|
||||
"Name": "File",
|
||||
"Args": {
|
||||
"path": "Logs/BusinessFlow/log-.txt",
|
||||
"rollingInterval": "Day",
|
||||
"outputTemplate": "[{Timestamp:yyyy-MM-dd HH:mm:ss} {Level:u3}] {Message:lj}{NewLine}{Exception}"
|
||||
}
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
]
|
||||
],
|
||||
"Enrich": [ "FromLogContext" ]
|
||||
},
|
||||
"AllowedHosts": "*",
|
||||
"Kestrel": {
|
||||
|
||||
@@ -128,6 +128,8 @@ namespace WorkFlowCheck.BL.Services
|
||||
var retVal = "";
|
||||
try
|
||||
{
|
||||
Log.ForContext("TAG", "AuditFlow").Information($"Bejelentkezési kísérlet: {userName}");
|
||||
|
||||
var user = await _dbContext.Users
|
||||
.Include(i => i.UserRoles)
|
||||
.ThenInclude(i => i.Role)
|
||||
@@ -154,11 +156,15 @@ namespace WorkFlowCheck.BL.Services
|
||||
user.Email,
|
||||
}, "Bejelentkezés megerősítése",
|
||||
Get2FConfirmationMessageBody(code));
|
||||
|
||||
Log.ForContext("TAG", "AuditFlow").Information($"Bejelentkezési kísérlet, email küldés: {user.Email}");
|
||||
retVal = CodeGenerator2F.GenerateToken2F(userName, password, code);
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext("TAG", "AuditFlow").Error($"Sikertelen bejelentkezési kísérlet: {userName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
@@ -198,9 +204,14 @@ namespace WorkFlowCheck.BL.Services
|
||||
await _dbContext.SaveChangesAsync();
|
||||
|
||||
retVal = _mapper.Map<UserDTO>(user);
|
||||
Log.ForContext("TAG", "AuditFlow").Information($"Sikeres azonosítás!: {userName}");
|
||||
return retVal;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Log.ForContext("TAG", "AuditFlow").Error($"Sikertelen bejelentkezési kísérlet: {userName}");
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user