• C#读取Windows日志


    可以再global中记录日志到数据库中
       //记录ASP.NET站点中未处理的异常
            protected void Application_Error(object sender, EventArgs e)
            {
                Exception ex = Server.GetLastError().GetBaseException();
                LogEntry log = new LogEntry();
                log.Categories.Add("General");
                log.Title = "未处理的异常";
                log.EventId = 1;
                log.Message = ex.Message +
                                "\r\nSOURCE: " + ex.Source +
                                "\r\nFORM: " + Request.Form.ToString() +
                                "\r\nQUERYSTRING: " + Request.QueryString.ToString() +
                                "\r\nTARGETSITE: " + ex.TargetSite +
                                "\r\nSTACKTRACE: " + ex.StackTrace;
                Logger.Write(log);
            }

    测试环境:.Net Framework 2.0、Windows Server 2003 SP2、Visual Studio 2005 SP1

    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using System.Text;

    using System.Diagnostics;

    public partial class Default3 : System.Web.UI.Page
    {
        
    protected void Page_Load(object sender, EventArgs e)
         {
            
    //Windows日志有:"Application"应用程序, "Security"安全, "System"系统
            string[] logs = new string[] { "Application", "System" };

             StringBuilder result
    = new StringBuilder();

            
    foreach (string log in logs)
             {
                 EventLog myLog
    = new EventLog();
                 myLog.Log
    = log;
                
    //myLog.MachineName = "rondi-agt0qf9op";
                foreach (EventLogEntry entry in myLog.Entries)
                 {
                    
    //EventLogEntryType枚举包括:
                    
    //Error 错误事件。
                    
    //FailureAudit 失败审核事件。
                    
    //Information 信息事件。
                    
    //SuccessAudit 成功审核事件。
                    
    //Warning 警告事件。
                    if (entry.EntryType == EventLogEntryType.Error || entry.EntryType == EventLogEntryType.Warning)
                     {
                         result.Append(
    "<font color='red'>" + log);
                         result.Append(entry.EntryType.ToString()
    + "</font>");
                         result.Append(
    "<font color='blue'>(" + entry.TimeWritten.ToString() + ")</font>:");
                         result.Append(entry.Message
    + "<br /><br />");
                     }
                 }
             }
             Response.Write(result.ToString());
         }
    }
    输出结果:

    ApplicationWarning(2007-6-16 16:25:49):Event code: 3005 Event message: 发生了未处理的异常。 Event time: 2007-6-16 16:25:49 Event time (UTC)

    SystemWarning(2007-6-16 10:34:15):浏览器服务不能从在网络 \Device\NetBT_Tcpip_{5AC78E63-D3B3-4246-8FF7-D8D2B41B3620} 上的主浏览器 \\QIANTING01 上检索服务器列表。 主浏览器: \\QIANTING01 网络: \Device\NetBT_Tcpip_{5AC78E63-D3B3-4246-8FF7-D8D2B41B3620} 此事件可能是由于暂时丢失网络连接造成的。如果此消息再次出现,请确认服务器仍然与网络连接。返回码在数据文本框中。

    SystemError(2007-6-16 10:34:45):浏览器服务已很多次无法在 \Device\NetBT_Tcpip_{5AC78E63-D3B3-4246-8FF7-D8D2B41B3620} 传输上捕获备份列表。备份浏览器已经停止。

    SystemError(2007-6-16 15:40:30):浏览器服务已很多次无法在 \Device\NetBT_Tcpip_{5AC78E63-D3B3-4246-8FF7-D8D2B41B3620} 传输上捕获备份列表。备份浏览器已经停止。

  • 相关阅读:
    yum -y list java* 查看当前java的版本
    max number of threads [1024] for user [lish] likely too low, increase to at least [2048]
    max file descriptors [4096] for elasticsearch process likely too low, increase to at least [65536]
    max virtual memory areas vm.max_map_count [65530] likely too low, increase to at least [262144]
    linux文件描述符open file descriptors与open files的区别
    samba 报错
    检测端口是否开启
    sqlserver2008出现数据库主体在该数据库中拥有架构,无法删除的解决方案
    sqlserver生成表结构文档的方法
    胡萝卜周博客 软件下载
  • 原文地址:https://www.cnblogs.com/aaa6818162/p/1540226.html
Copyright © 2020-2023  润新知