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.Common.RequestContext;
|
||||||
using WorkFlowCheck.API.RequestContext;
|
using WorkFlowCheck.API.RequestContext;
|
||||||
using WorkFlowCheck.API.Middleware;
|
using WorkFlowCheck.API.Middleware;
|
||||||
|
using Serilog.Filters;
|
||||||
|
|
||||||
var builder = WebApplication.CreateBuilder(args);
|
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()
|
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();
|
.CreateLogger();
|
||||||
|
|
||||||
|
|
||||||
|
//------------------------------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
|
||||||
|
Log.ForContext("TAG", "BusinessFlow").Information("API indítása...");
|
||||||
|
|
||||||
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
builder.Services.AddAutoMapper(typeof(MapperProfile));
|
||||||
builder.Services.AddMemoryCache();
|
builder.Services.AddMemoryCache();
|
||||||
builder.Services.AddHttpContextAccessor();
|
builder.Services.AddHttpContextAccessor();
|
||||||
@@ -141,5 +171,7 @@ app.UseMiddleware<JwtMiddleware>();
|
|||||||
app.MapControllers();
|
app.MapControllers();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
app.UseCors();
|
app.UseCors();
|
||||||
|
|
||||||
|
Log.ForContext("TAG", "BusinessFlow").Information("API fut.");
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|
||||||
|
|||||||
@@ -42,14 +42,14 @@
|
|||||||
</None>
|
</None>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
<ItemGroup>
|
|
||||||
<Folder Include="logs\" />
|
|
||||||
</ItemGroup>
|
|
||||||
|
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Content Update="appsettings.Development.json">
|
<Content Update="appsettings.Development.json">
|
||||||
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
<CopyToOutputDirectory>Never</CopyToOutputDirectory>
|
||||||
</Content>
|
</Content>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<Folder Include="Logs\BusinessFlow\" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|||||||
@@ -24,11 +24,44 @@
|
|||||||
{
|
{
|
||||||
"Name": "File",
|
"Name": "File",
|
||||||
"Args": {
|
"Args": {
|
||||||
"path": "logs/log-.log",
|
"path": "Logs/log-.log",
|
||||||
"rollingInterval": "Day"
|
"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": "*",
|
"AllowedHosts": "*",
|
||||||
"Kestrel": {
|
"Kestrel": {
|
||||||
|
|||||||
@@ -128,6 +128,8 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
var retVal = "";
|
var retVal = "";
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
Log.ForContext("TAG", "AuditFlow").Information($"Bejelentkezési kísérlet: {userName}");
|
||||||
|
|
||||||
var user = await _dbContext.Users
|
var user = await _dbContext.Users
|
||||||
.Include(i => i.UserRoles)
|
.Include(i => i.UserRoles)
|
||||||
.ThenInclude(i => i.Role)
|
.ThenInclude(i => i.Role)
|
||||||
@@ -154,11 +156,15 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
user.Email,
|
user.Email,
|
||||||
}, "Bejelentkezés megerősítése",
|
}, "Bejelentkezés megerősítése",
|
||||||
Get2FConfirmationMessageBody(code));
|
Get2FConfirmationMessageBody(code));
|
||||||
|
Log.ForContext("TAG", "AuditFlow").Information($"Bejelentkezési kísérlet, email küldés: {user.Email}");
|
||||||
retVal = CodeGenerator2F.GenerateToken2F(userName, password, code);
|
retVal = CodeGenerator2F.GenerateToken2F(userName, password, code);
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.ForContext("TAG", "AuditFlow").Error($"Sikertelen bejelentkezési kísérlet: {userName}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
@@ -198,9 +204,14 @@ namespace WorkFlowCheck.BL.Services
|
|||||||
await _dbContext.SaveChangesAsync();
|
await _dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
retVal = _mapper.Map<UserDTO>(user);
|
retVal = _mapper.Map<UserDTO>(user);
|
||||||
|
Log.ForContext("TAG", "AuditFlow").Information($"Sikeres azonosítás!: {userName}");
|
||||||
return retVal;
|
return retVal;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
Log.ForContext("TAG", "AuditFlow").Error($"Sikertelen bejelentkezési kísérlet: {userName}");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception ex)
|
catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user