学习完王磊先生的文章:ASP.NET 2.0中的健康监测系统(Health Monitoring)
http://www.cnblogs.com/webabcd/archive/2007/05/20/753507.html
就有了这篇文章

目前基本了解到写入系统日志的方法有三种:
①EIF(Enterprise Implementation Framework),很强大的工具,我上项目中已使用.
我自己创建了一个Web Site项目,进行配置,搞了半天,失败!
难道Web Site项目不适合用EIF,还是本人愚钝,高手的说话.
这里有详细的配置步骤:http://msdn2.microsoft.com/en-us/library/ms979206.aspx

②我自己写了个DLL,感觉很好用!
(基本为王磊先生文章的一个扩展)
    1.创建一个Web Site项目.
    2.引入DLL(LogLibrary_AX.dll)
    3.使用Log类的LogInfo/LogWarning方法进行日志的写入.使用代码如下:
把项目运行情况写入系统日志(Log)的三种方法_AXusing System;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Data;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Configuration;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web.Security;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web.UI;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web.UI.WebControls;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web.UI.WebControls.WebParts;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web.UI.HtmlControls;
把项目运行情况写入系统日志(Log)的三种方法_AX
把项目运行情况写入系统日志(Log)的三种方法_AX
//This is my DLL,need import.
把项目运行情况写入系统日志(Log)的三种方法_AX
using LogLibrary_AX;
把项目运行情况写入系统日志(Log)的三种方法_AX
把项目运行情况写入系统日志(Log)的三种方法_AX
public partial class _Default : System.Web.UI.Page

    4.配置Web.config
      添加 HealthMonitoring 节点
把项目运行情况写入系统日志(Log)的三种方法_AX<?xml version="1.0"?>
把项目运行情况写入系统日志(Log)的三种方法_AX
<configuration>
把项目运行情况写入系统日志(Log)的三种方法_AX    
<appSettings/>
把项目运行情况写入系统日志(Log)的三种方法_AX    
<connectionStrings/>
把项目运行情况写入系统日志(Log)的三种方法_AX    
<system.web>
把项目运行情况写入系统日志(Log)的三种方法_AX           
<!--添加 HealthMonitoring 节点开始-->
把项目运行情况写入系统日志(Log)的三种方法_AX        
<healthMonitoring>
把项目运行情况写入系统日志(Log)的三种方法_AX            
<eventMappings>
把项目运行情况写入系统日志(Log)的三种方法_AX                
<add name="AX" type="LogLibrary_AX.LogInfo"/>
把项目运行情况写入系统日志(Log)的三种方法_AX            
</eventMappings>
把项目运行情况写入系统日志(Log)的三种方法_AX            
<rules>
把项目运行情况写入系统日志(Log)的三种方法_AX                
<add name="rule_AX" eventName="AX" provider="EventLogProvider"/>
把项目运行情况写入系统日志(Log)的三种方法_AX            
</rules>
把项目运行情况写入系统日志(Log)的三种方法_AX        
</healthMonitoring>    
把项目运行情况写入系统日志(Log)的三种方法_AX        
<!--添加 HealthMonitoring 节点结束-->
把项目运行情况写入系统日志(Log)的三种方法_AX        
<compilation debug="true"/>        
把项目运行情况写入系统日志(Log)的三种方法_AX        
<authentication mode="Windows"/>        
把项目运行情况写入系统日志(Log)的三种方法_AX    
</system.web>
把项目运行情况写入系统日志(Log)的三种方法_AX
</configuration>
把项目运行情况写入系统日志(Log)的三种方法_AX


LogLibrary_AX.dll源码如下
(下载链接:https://files.cnblogs.com/AXzhz/LogLibrary_AX.rar)
把项目运行情况写入系统日志(Log)的三种方法_AXusing System;
把项目运行情况写入系统日志(Log)的三种方法_AX
using System.Web.Management;
把项目运行情况写入系统日志(Log)的三种方法_AX
把项目运行情况写入系统日志(Log)的三种方法_AX
namespace LogLibrary_AX

运行结果:
把项目运行情况写入系统日志(Log)的三种方法_AX

③使用Diagnostics.EventLog类,很easy的方法.我不想用的说.
参见:http://msdn.microsoft.com/library/chs/default.asp?url=/library/CHS/cpref/html/frlrfsystemdiagnosticseventlogclasstopic.asp


---------------------------------------------------
【总结】
方法①很好,很强大.
方法②不能出带红×的信息类型,也不能创建一个和Application同级的节点.(会的说话)
方法③可以创建一个和Application同级的节点,参见上图MyNowLog节点,但是好像出来的类型都是Information
(会出别的的说话)

博客园斧头帮少帮主

相关文章:

  • 2021-10-17
  • 2021-08-04
  • 2021-12-30
  • 2021-10-10
  • 2021-08-17
  • 2022-01-20
  • 2021-08-12
  • 2022-12-23
猜你喜欢
  • 2021-07-28
  • 2022-12-23
  • 2022-12-23
  • 2021-07-15
  • 2021-11-19
  • 2021-11-01
  • 2022-01-05
相关资源
相似解决方案