Resolve a critical error in new logging code (#231)
This commit is contained in:
@@ -1,5 +1,4 @@
|
|||||||
using System;
|
using System.Collections.Concurrent;
|
||||||
using System.Collections.Concurrent;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
|
||||||
namespace gaseous_server.Classes
|
namespace gaseous_server.Classes
|
||||||
@@ -137,5 +136,4 @@ namespace gaseous_server.Classes
|
|||||||
public static object GetData(string name) =>
|
public static object GetData(string name) =>
|
||||||
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
|
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@@ -76,24 +76,38 @@ namespace gaseous_server.Classes
|
|||||||
}
|
}
|
||||||
|
|
||||||
string correlationId;
|
string correlationId;
|
||||||
if (CallContext.GetData("CorrelationId").ToString() == null)
|
try
|
||||||
|
{
|
||||||
|
if (CallContext.GetData("CorrelationId").ToString() == null)
|
||||||
|
{
|
||||||
|
correlationId = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
correlationId = CallContext.GetData("CorrelationId").ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
correlationId = "";
|
correlationId = "";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
correlationId = CallContext.GetData("CorrelationId").ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
string callingProcess;
|
string callingProcess;
|
||||||
if (CallContext.GetData("CallingProcess").ToString() == null)
|
try
|
||||||
|
{
|
||||||
|
if (CallContext.GetData("CallingProcess").ToString() == null)
|
||||||
|
{
|
||||||
|
callingProcess = "";
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
callingProcess = CallContext.GetData("CallingProcess").ToString();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch
|
||||||
{
|
{
|
||||||
callingProcess = "";
|
callingProcess = "";
|
||||||
}
|
}
|
||||||
else
|
|
||||||
{
|
|
||||||
callingProcess = CallContext.GetData("CallingProcess").ToString();
|
|
||||||
}
|
|
||||||
|
|
||||||
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
|
||||||
string sql = "DELETE FROM ServerLogs WHERE EventTime < @EventRententionDate; INSERT INTO ServerLogs (EventTime, EventType, Process, Message, Exception, CorrelationId, CallingProcess) VALUES (@EventTime, @EventType, @Process, @Message, @Exception, @correlationid, @callingprocess);";
|
string sql = "DELETE FROM ServerLogs WHERE EventTime < @EventRententionDate; INSERT INTO ServerLogs (EventTime, EventType, Process, Message, Exception, CorrelationId, CallingProcess) VALUES (@EventTime, @EventType, @Process, @Message, @Exception, @correlationid, @callingprocess);";
|
||||||
|
@@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
|
|||||||
[ApiVersion("1.1")]
|
[ApiVersion("1.1")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class FilterController : ControllerBase
|
public class FilterController : Controller
|
||||||
{
|
{
|
||||||
private readonly UserManager<ApplicationUser> _userManager;
|
private readonly UserManager<ApplicationUser> _userManager;
|
||||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||||
|
@@ -22,7 +22,7 @@ namespace gaseous_server.Controllers
|
|||||||
[ApiVersion("1.1")]
|
[ApiVersion("1.1")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class GamesController : ControllerBase
|
public class GamesController : Controller
|
||||||
{
|
{
|
||||||
[MapToApiVersion("1.0")]
|
[MapToApiVersion("1.0")]
|
||||||
[HttpGet]
|
[HttpGet]
|
||||||
|
@@ -22,7 +22,7 @@ namespace gaseous_server.Controllers
|
|||||||
[ApiVersion("1.1")]
|
[ApiVersion("1.1")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
[ApiController]
|
[ApiController]
|
||||||
public class RomsController : ControllerBase
|
public class RomsController : Controller
|
||||||
{
|
{
|
||||||
[MapToApiVersion("1.0")]
|
[MapToApiVersion("1.0")]
|
||||||
[MapToApiVersion("1.1")]
|
[MapToApiVersion("1.1")]
|
||||||
|
@@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
|
|||||||
[ApiVersion("1.0")]
|
[ApiVersion("1.0")]
|
||||||
[ApiVersion("1.1")]
|
[ApiVersion("1.1")]
|
||||||
[Authorize]
|
[Authorize]
|
||||||
public class SignaturesController : ControllerBase
|
public class SignaturesController : Controller
|
||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the current signature counts from the database
|
/// Get the current signature counts from the database
|
||||||
|
@@ -295,29 +295,22 @@ using (var scope = app.Services.CreateScope())
|
|||||||
await roleManager.CreateAsync(applicationRole, CancellationToken.None);
|
await roleManager.CreateAsync(applicationRole, CancellationToken.None);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// // set up administrator account
|
|
||||||
// var userManager = scope.ServiceProvider.GetRequiredService<UserStore>();
|
|
||||||
// if (await userManager.FindByNameAsync("admin@localhost", CancellationToken.None) == null)
|
|
||||||
// {
|
|
||||||
// ApplicationUser adminUser = new ApplicationUser{
|
|
||||||
// Id = Guid.NewGuid().ToString(),
|
|
||||||
// Email = "admin@localhost",
|
|
||||||
// NormalizedEmail = "ADMIN@LOCALHOST",
|
|
||||||
// EmailConfirmed = true,
|
|
||||||
// UserName = "administrator",
|
|
||||||
// NormalizedUserName = "ADMINISTRATOR"
|
|
||||||
// };
|
|
||||||
|
|
||||||
// //set user password
|
|
||||||
// PasswordHasher<ApplicationUser> ph = new PasswordHasher<ApplicationUser>();
|
|
||||||
// adminUser.PasswordHash = ph.HashPassword(adminUser, "letmein");
|
|
||||||
|
|
||||||
// await userManager.CreateAsync(adminUser, CancellationToken.None);
|
|
||||||
// await userManager.AddToRoleAsync(adminUser, "Admin", CancellationToken.None);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
app.Use(async (context, next) =>
|
||||||
|
{
|
||||||
|
// set the correlation id
|
||||||
|
string correlationId = Guid.NewGuid().ToString();
|
||||||
|
CallContext.SetData("CorrelationId", correlationId);
|
||||||
|
CallContext.SetData("CallingProcess", context.Request.Method + ": " + context.Request.Path);
|
||||||
|
|
||||||
|
context.Response.Headers.Add("x-correlation-id", correlationId.ToString());
|
||||||
|
await next();
|
||||||
|
});
|
||||||
|
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.UseDefaultFiles();
|
app.UseDefaultFiles();
|
||||||
|
@@ -21,6 +21,6 @@ ADD INDEX `idx_SecondaryColumn` (`ThemesId` ASC) VISIBLE;
|
|||||||
|
|
||||||
ALTER TABLE `ServerLogs`
|
ALTER TABLE `ServerLogs`
|
||||||
ADD COLUMN `CorrelationId` VARCHAR(45) NULL AFTER `Exception`,
|
ADD COLUMN `CorrelationId` VARCHAR(45) NULL AFTER `Exception`,
|
||||||
ADD COLUMN `CallingProcess` VARCHAR(45) NULL AFTER `CorrelationId`,
|
ADD COLUMN `CallingProcess` VARCHAR(255) NULL AFTER `CorrelationId`,
|
||||||
ADD INDEX `idx_CorrelationId` (`CorrelationId` ASC) VISIBLE,
|
ADD INDEX `idx_CorrelationId` (`CorrelationId` ASC) VISIBLE,
|
||||||
ADD INDEX `idx_CallingProcess` (`CallingProcess` ASC) VISIBLE;
|
ADD INDEX `idx_CallingProcess` (`CallingProcess` ASC) VISIBLE;
|
Reference in New Issue
Block a user