log4net 1.2.11.0
I am trying to get anything that will allow me to log with a unique value for each ASP.NET request.
I tried %thread, but threads appear to
Here's some extension methods that I created for this purpose:
public static Guid GetId(this HttpContext ctx) => new HttpContextWrapper(ctx).GetId();
public static Guid GetId(this HttpContextBase ctx)
{
const string key = "tq8OuyxHpDgkRg54klfpqg== (Request Id Key)";
if (ctx.Items.Contains(key))
return (Guid) ctx.Items[key];
var mutex = string.Intern($"{key}:{ctx.GetHashCode()}");
lock (mutex)
{
if (!ctx.Items.Contains(key))
ctx.Items[key] = Guid.NewGuid();
return (Guid) ctx.Items[key];
}
}