[C#,ASP.NET]이벤트뷰어, 이벤트로그 보기예제
꽁스짱
ASP.NET
0
1177
2021.02.17 02:05
[C#,ASP.NET]이벤트뷰어, 이벤트로그 보기예제
[EventLogViewer.aspx]
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="EventLogViewer.aspx.cs" Inherits="WebApplication5.EventLogViewer" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
ASP.NET 이벤트 로그 보기<br />
<br />
<br />
<asp:Button ID="Button1" runat="server" onclick="Button1_Click"
Text="이벤트 로그 보기" />
<br />
<br />
<asp:ListBox ID="ListBox1" runat="server" Height="383px" Width="751px">
</asp:ListBox>
<br />
</div>
</form>
</body>
</html>
[EventLogViewer.aspx.cs]
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Diagnostics;
namespace WebApplication5
{
public partial class EventLogViewer : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
EventLog ev = new EventLog("MyEvent2");
try
{
if (ev.Entries.Count > 0)
{
foreach (System.Diagnostics.EventLogEntry entry in ev.Entries)
{
ListBox1.Items.Add(entry.Message);
}
}
else
{
//MessageBox.Show("There are no entries in the log."); ListBox1.Items.Add("Event Log Not Found...");
}
}
catch (Exception b)
{
Response.Write("ReadEntry " + b.Message + "<br>");
}
ev = null;
}
}
}