积极答复者
获取IIS网站的记录日志内容

问题
答案
-
是不是我思路错了,想用代码来获取用户访问网站的时间和域用户名(域内的网站)
我觉得log4net是符合你的要求的。通过代码来控制是否往日志文件里面写入内容。 详细可以看这里, http://www.cnblogs.com/Heroman/archive/2006/01/09/314053.html
操作步骤一般为:
- 从Nuget Manager里面下载log4net
- 配置web.config文件
- 从下面的代码中获得windows 用户名然后连同时间写到log里面就可以了
(System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal).Identity.Name
希望能够帮到你。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Herro wongMicrosoft contingent staff 2016年4月28日 3:13
- 已标记为答案 Zhanglong WuMicrosoft contingent staff, Moderator 2016年5月5日 7:44
全部回复
-
你好,有两种方法解决你的问题。
1. 保持默认的txt文件记录log的方式,可以自己实现或者下载 IIS 日志分析器,把结果保存到数据库中,方便查询。
google一下iis log analyzer会找到很多工具。
2. 使用ODBC方式保存IIS日志,这样日志写到数据库中,直接查询就可以。
IIS6参考: How to configure ODBC logging in IIS
IIS7参考: IIS7 – post #57 – How to setup ODBC Logging in IIS 7.0/7.5
日志中的UserName就是你需要的和Datetime是你需要的fields.
-
是不是我思路错了,想用代码来获取用户访问网站的时间和域用户名(域内的网站)
我觉得log4net是符合你的要求的。通过代码来控制是否往日志文件里面写入内容。 详细可以看这里, http://www.cnblogs.com/Heroman/archive/2006/01/09/314053.html
操作步骤一般为:
- 从Nuget Manager里面下载log4net
- 配置web.config文件
- 从下面的代码中获得windows 用户名然后连同时间写到log里面就可以了
(System.Threading.Thread.CurrentPrincipal as System.Security.Principal.WindowsPrincipal).Identity.Name
希望能够帮到你。We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
Click HERE to participate the survey.- 已建议为答案 Herro wongMicrosoft contingent staff 2016年4月28日 3:13
- 已标记为答案 Zhanglong WuMicrosoft contingent staff, Moderator 2016年5月5日 7:44