logdemo.aspx
来自「C#开发者可使用的经典案例集,源自于ASP.NET经典范例50讲」· ASPX 代码 · 共 43 行
ASPX
43 行
<%@ Import Namespace="System.Diagnostics" %>
<%@ Page Language="C#" Debug="true" %>
<html>
<head>
<title>Log Demo</title>
<script language="C#" runat="server" >
void OnInformation(object sender, EventArgs arg)
{
string logName = ConfigurationSettings.AppSettings["EventLogName"];
string logSource = ConfigurationSettings.AppSettings["EventLogSource"];
if(!(EventLog.SourceExists(logSource)))
{
EventLog.CreateEventSource(logSource, logName);
}
EventLog log = new EventLog();
log.Source = logSource;
log.WriteEntry(TextBox1.Text, EventLogEntryType.Information);
}
void OnException(object sender, EventArgs arg)
{
Exception e = new Exception(TextBox1.Text);
throw(e);
}
</script>
</head>
<body>
<form id="form1" runat="server">
<h3>Log Demo</h3>
日志内容<br/>
<asp:TextBox id="TextBox1" runat="server"
Columns="45" Rows="6" TextMode="MultiLine" />
<hr/>
<asp:Button id="ButtonInformation" runat="server" Text="记录日志"
OnClick="OnInformation"/>
<asp:Button id="ButtonException" runat="server" Text="错误日志"
OnClick="OnException" />
</form>
</body>
</html>
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?