Skip to content

Commit

Permalink
Resolve a critical error in new logging code (#231)
Browse files Browse the repository at this point in the history
  • Loading branch information
michael-j-green authored Dec 13, 2023
1 parent 907b3e4 commit b691eab
Show file tree
Hide file tree
Showing 8 changed files with 43 additions and 38 deletions.
6 changes: 2 additions & 4 deletions gaseous-server/Classes/Common.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using System;
using System.Collections.Concurrent;
using System.Collections.Concurrent;
using System.Security.Cryptography;

namespace gaseous_server.Classes
Expand Down Expand Up @@ -137,5 +136,4 @@ public static void SetData(string name, object data) =>
public static object GetData(string name) =>
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
}
}

}
30 changes: 22 additions & 8 deletions gaseous-server/Classes/Logging.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,23 +76,37 @@ static public void Log(LogType EventType, string ServerProcess, string Message,
}

string correlationId;
if (CallContext.GetData("CorrelationId").ToString() == null)
try
{
correlationId = "";
if (CallContext.GetData("CorrelationId").ToString() == null)
{
correlationId = "";
}
else
{
correlationId = CallContext.GetData("CorrelationId").ToString();
}
}
else
catch
{
correlationId = CallContext.GetData("CorrelationId").ToString();
correlationId = "";
}

string callingProcess;
if (CallContext.GetData("CallingProcess").ToString() == null)
try
{
callingProcess = "";
if (CallContext.GetData("CallingProcess").ToString() == null)
{
callingProcess = "";
}
else
{
callingProcess = CallContext.GetData("CallingProcess").ToString();
}
}
else
catch
{
callingProcess = CallContext.GetData("CallingProcess").ToString();
callingProcess = "";
}

Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Controllers/V1.0/FilterController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
[ApiVersion("1.1")]
[Authorize]
[ApiController]
public class FilterController : ControllerBase
public class FilterController : Controller
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Controllers/V1.0/GamesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace gaseous_server.Controllers
[ApiVersion("1.1")]
[Authorize]
[ApiController]
public class GamesController : ControllerBase
public class GamesController : Controller
{
[MapToApiVersion("1.0")]
[HttpGet]
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Controllers/V1.0/RomsController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ namespace gaseous_server.Controllers
[ApiVersion("1.1")]
[Authorize]
[ApiController]
public class RomsController : ControllerBase
public class RomsController : Controller
{
[MapToApiVersion("1.0")]
[MapToApiVersion("1.1")]
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Controllers/V1.0/SignaturesController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
[ApiVersion("1.0")]
[ApiVersion("1.1")]
[Authorize]
public class SignaturesController : ControllerBase
public class SignaturesController : Controller
{
/// <summary>
/// Get the current signature counts from the database
Expand Down
35 changes: 14 additions & 21 deletions gaseous-server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -295,29 +295,22 @@
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.UseDefaultFiles();
Expand Down
2 changes: 1 addition & 1 deletion gaseous-server/Support/Database/MySQL/gaseous-1008.sql
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,6 @@ ADD INDEX `idx_SecondaryColumn` (`ThemesId` ASC) VISIBLE;

ALTER TABLE `ServerLogs`
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_CallingProcess` (`CallingProcess` ASC) VISIBLE;

0 comments on commit b691eab

Please sign in to comment.