我怎么能包括的SessionID在ASP.NET中使用log4net的日志文件? [英] How can I include SessionID in log files using log4net in ASP.NET?
问题描述
我是新来log4net的,所以希望这是一个人真正简单的问题?!
I'm new to log4net, so hopefully this is a really easy question for someone?!
我已经得到的log4net与RollingLogFileAppender工作为我的Web应用程序。我使用的记录,试图找到在哪里一些性能问题的来源。为了做到这一点,它会是有用的包括ASP.NET的SessionID在日志输出,这样我可以确保我在看日志条目为特定用户。
I've got log4net working with the RollingLogFileAppender for my web application. I'm using logging to try and find where some performance issues are coming from. In order to do this, it'd be useful to include the ASP.NET SessionID in the log output so that I can make sure I'm looking at log entries for a specific user.
有什么办法,我可以通过 conversionPattern
设置的附加目的地做到这一点?是否有一个%{财产??}
设置可以使用吗?
Is there any way I can do this through the conversionPattern
setting for the appender? Is there a %property{??}
setting I can use?
更新:这个问题仍然没有得到答复 - 没有任何人有任何想法
推荐答案
亚历山大K.几乎是正确的。它唯一的问题是, PostAcquireRequestState
事件也发生了静态请求。在这种情况下,以会话的调用将导致 HttpException
。
Alexander K. is nearly correct. The only problem with it is that the PostAcquireRequestState
event also occurs for static requests. A call to Session in this situation will cause a HttpException
.
因此,正确的解决办法就变成了:
Therefore the correct solution becomes:
protected void Application_PostAcquireRequestState(object sender, EventArgs e)
{
if (Context.Handler is IRequiresSessionState)
{
log4net.ThreadContext.Properties["SessionId"] = Session.SessionID;
}
}
这篇关于我怎么能包括的SessionID在ASP.NET中使用log4net的日志文件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!