Skip to content

Commit b691eab

Browse files
Resolve a critical error in new logging code (#231)
1 parent 907b3e4 commit b691eab

File tree

8 files changed

+43
-38
lines changed

8 files changed

+43
-38
lines changed

gaseous-server/Classes/Common.cs

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
using System;
2-
using System.Collections.Concurrent;
1+
using System.Collections.Concurrent;
32
using System.Security.Cryptography;
43

54
namespace gaseous_server.Classes
@@ -137,5 +136,4 @@ public static void SetData(string name, object data) =>
137136
public static object GetData(string name) =>
138137
state.TryGetValue(name, out AsyncLocal<object> data) ? data.Value : null;
139138
}
140-
}
141-
139+
}

gaseous-server/Classes/Logging.cs

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -76,23 +76,37 @@ static public void Log(LogType EventType, string ServerProcess, string Message,
7676
}
7777

7878
string correlationId;
79-
if (CallContext.GetData("CorrelationId").ToString() == null)
79+
try
8080
{
81-
correlationId = "";
81+
if (CallContext.GetData("CorrelationId").ToString() == null)
82+
{
83+
correlationId = "";
84+
}
85+
else
86+
{
87+
correlationId = CallContext.GetData("CorrelationId").ToString();
88+
}
8289
}
83-
else
90+
catch
8491
{
85-
correlationId = CallContext.GetData("CorrelationId").ToString();
92+
correlationId = "";
8693
}
8794

8895
string callingProcess;
89-
if (CallContext.GetData("CallingProcess").ToString() == null)
96+
try
9097
{
91-
callingProcess = "";
98+
if (CallContext.GetData("CallingProcess").ToString() == null)
99+
{
100+
callingProcess = "";
101+
}
102+
else
103+
{
104+
callingProcess = CallContext.GetData("CallingProcess").ToString();
105+
}
92106
}
93-
else
107+
catch
94108
{
95-
callingProcess = CallContext.GetData("CallingProcess").ToString();
109+
callingProcess = "";
96110
}
97111

98112
Database db = new Database(Database.databaseType.MySql, Config.DatabaseConfiguration.ConnectionString);

gaseous-server/Controllers/V1.0/FilterController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
1818
[ApiVersion("1.1")]
1919
[Authorize]
2020
[ApiController]
21-
public class FilterController : ControllerBase
21+
public class FilterController : Controller
2222
{
2323
private readonly UserManager<ApplicationUser> _userManager;
2424
private readonly SignInManager<ApplicationUser> _signInManager;

gaseous-server/Controllers/V1.0/GamesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace gaseous_server.Controllers
2222
[ApiVersion("1.1")]
2323
[Authorize]
2424
[ApiController]
25-
public class GamesController : ControllerBase
25+
public class GamesController : Controller
2626
{
2727
[MapToApiVersion("1.0")]
2828
[HttpGet]

gaseous-server/Controllers/V1.0/RomsController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ namespace gaseous_server.Controllers
2222
[ApiVersion("1.1")]
2323
[Authorize]
2424
[ApiController]
25-
public class RomsController : ControllerBase
25+
public class RomsController : Controller
2626
{
2727
[MapToApiVersion("1.0")]
2828
[MapToApiVersion("1.1")]

gaseous-server/Controllers/V1.0/SignaturesController.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ namespace gaseous_server.Controllers
1818
[ApiVersion("1.0")]
1919
[ApiVersion("1.1")]
2020
[Authorize]
21-
public class SignaturesController : ControllerBase
21+
public class SignaturesController : Controller
2222
{
2323
/// <summary>
2424
/// Get the current signature counts from the database

gaseous-server/Program.cs

Lines changed: 14 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -295,29 +295,22 @@
295295
await roleManager.CreateAsync(applicationRole, CancellationToken.None);
296296
}
297297
}
298-
299-
// // set up administrator account
300-
// var userManager = scope.ServiceProvider.GetRequiredService<UserStore>();
301-
// if (await userManager.FindByNameAsync("admin@localhost", CancellationToken.None) == null)
302-
// {
303-
// ApplicationUser adminUser = new ApplicationUser{
304-
// Id = Guid.NewGuid().ToString(),
305-
// Email = "admin@localhost",
306-
// NormalizedEmail = "ADMIN@LOCALHOST",
307-
// EmailConfirmed = true,
308-
// UserName = "administrator",
309-
// NormalizedUserName = "ADMINISTRATOR"
310-
// };
311-
312-
// //set user password
313-
// PasswordHasher<ApplicationUser> ph = new PasswordHasher<ApplicationUser>();
314-
// adminUser.PasswordHash = ph.HashPassword(adminUser, "letmein");
315-
316-
// await userManager.CreateAsync(adminUser, CancellationToken.None);
317-
// await userManager.AddToRoleAsync(adminUser, "Admin", CancellationToken.None);
318-
// }
319298
}
320299

300+
301+
302+
303+
app.Use(async (context, next) =>
304+
{
305+
// set the correlation id
306+
string correlationId = Guid.NewGuid().ToString();
307+
CallContext.SetData("CorrelationId", correlationId);
308+
CallContext.SetData("CallingProcess", context.Request.Method + ": " + context.Request.Path);
309+
310+
context.Response.Headers.Add("x-correlation-id", correlationId.ToString());
311+
await next();
312+
});
313+
321314
app.UseAuthorization();
322315

323316
app.UseDefaultFiles();

gaseous-server/Support/Database/MySQL/gaseous-1008.sql

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,6 @@ ADD INDEX `idx_SecondaryColumn` (`ThemesId` ASC) VISIBLE;
2121

2222
ALTER TABLE `ServerLogs`
2323
ADD COLUMN `CorrelationId` VARCHAR(45) NULL AFTER `Exception`,
24-
ADD COLUMN `CallingProcess` VARCHAR(45) NULL AFTER `CorrelationId`,
24+
ADD COLUMN `CallingProcess` VARCHAR(255) NULL AFTER `CorrelationId`,
2525
ADD INDEX `idx_CorrelationId` (`CorrelationId` ASC) VISIBLE,
2626
ADD INDEX `idx_CallingProcess` (`CallingProcess` ASC) VISIBLE;

0 commit comments

Comments
 (0)