log4net unique request id in ASP.NET

HttpContext.Current.Items - is a good idea.

Try to add something like thit:

HttpContext.Current.Items.Add("RequestIdentity", Guid.NewGuid().ToString())

In .NET Core you can access it this way (from your controllers) HttpContext.Items and using HttpContextAccessor from anywhere else.

All the details here.


clock tick + process ID + thread ID as stored when your request starts should be sufficient, I think (assuming each thread handles 1 request at a time).


.asmx files will still call Application_BeginRequest event where you can store your unique GUID in HttpContext.Current.Items (using this collection avoid the odd problem when the request processing jumps threads). Only if you were using WCF (and also then it depends on configuration) this would not work.

If you would like not to touch the application itself, you can use HttpContext.Current.Timestamp that returns the time when the request processing started. Join that with your existing approach of getting the ID of the thread and you will get a unique value.