none
获取IIS网站的记录日志内容 RRS feed

  • 问题

  • 有没有不通过txt文件或者目录存放路径获取日志内容的方法呢?

    最好是C#代码,有没有大神有思路?求指点啊

    2016年4月20日 6:09

答案

  • 是不是我思路错了,想用代码来获取用户访问网站的时间和域用户名(域内的网站)

    我觉得log4net是符合你的要求的。通过代码来控制是否往日志文件里面写入内容。 详细可以看这里, http://www.cnblogs.com/Heroman/archive/2006/01/09/314053.html

    操作步骤一般为:

    1. 从Nuget Manager里面下载log4net
    2. 配置web.config文件
    3. 从下面的代码中获得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.

    2016年4月25日 6:51

全部回复

  • 是不是我思路错了,想用代码来获取用户访问网站的时间和域用户名(域内的网站)
    2016年4月20日 7:52
  • 你好,有两种方法解决你的问题。

    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.

    2016年4月21日 2:42
  • 是不是我思路错了,想用代码来获取用户访问网站的时间和域用户名(域内的网站)

    我觉得log4net是符合你的要求的。通过代码来控制是否往日志文件里面写入内容。 详细可以看这里, http://www.cnblogs.com/Heroman/archive/2006/01/09/314053.html

    操作步骤一般为:

    1. 从Nuget Manager里面下载log4net
    2. 配置web.config文件
    3. 从下面的代码中获得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.

    2016年4月25日 6:51