扫一扫
分享文章到微信
扫一扫
关注官方公众号
至顶头条
作者:xupc 来源:论坛 2007年10月17日
关键字:
Imports System.Diagnostics Imports System.Configuration.Install Imports System.ComponentModel <RunInstaller(True)> _ Public Class MyEventLogInstaller Inherits Installer Private myEventLogInstaller As EventLogInstaller Public Sub New() ' Create an instance of 'EventLogInstaller'. myEventLogInstaller = New EventLogInstaller() ' Set the 'Source' of the event log, to be created. myEventLogInstaller.Source = "TEST" ' Set the 'Log' that the source is created in. myEventLogInstaller.Log = "Application" ' Add myEventLogInstaller to 'InstallerCollection'. Installers.Add(myEventLogInstaller) End Sub End Class Visual C# .NET Sample using System; using System.Diagnostics; using System.ComponentModel; using System.Configuration.Install; namespace EventLogSourceInstaller { [RunInstaller(true)] public class MyEventLogInstaller : Installer { private EventLogInstaller myEventLogInstaller; public MyEventLogInstaller() { //Create Instance of EventLogInstaller myEventLogInstaller = new EventLogInstaller(); // Set the Source of Event Log, to be created. myEventLogInstaller.Source = "TEST"; // Set the Log that source is created in myEventLogInstaller.Log = "Application"; // Add myEventLogInstaller to the Installers Collection. Installers.Add(myEventLogInstaller); } } } |
5. 生成此项目,得到EventLogSourceInstaller.dll。
6. 打开Visual Studio .NET 命令提示,转到EventLogSourceInstaller.dll所在目录。
7. 运行此命令来创建“事件来源”:InstallUtil EventLogSourceInstaller.dll
更详尽的信息
我们通过一个创建一个Web Application来重现以上错误以及解决此问题。
1. 使用VB.Net或C#建立一个Asp.net Web Application。
2. 在WebForm1.aspx中的代码替换为以下代码:
Visual Basic .NET Sample
<%@ Page Language="vb" AutoEventWireup="true" %> <%@ Import namespace="System.Diagnostics" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <script language="VB" runat="server"> Sub WriteEvent_Click(Src As Object, e As EventArgs) Dim ev As New EventLog("Application") ' Event's Source name ev.Source = "TEST" EventLog.CreateEventSource(ev.Source, "Application") Try ev.WriteEntry(TextBox1.Text) Catch b as exception Response.write ("WriteEntry " & b.message & "<br>") End Try ev = Nothing End Sub </script> <body> <form id="Form1" runat="server"> Event message: <asp:textbox id="TextBox1" runat="server" Width="233px"></asp:textbox> <asp:button id="Button1" onclick="WriteEvent_Click" runat="server" NAME="Button1" text="Write to event log"></asp:button> </form> </body> </HTML> Visual C# .NET Sample <%@ Page Language="c#" AutoEventWireup="true" %> <%@ Import namespace="System.Diagnostics" %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <HTML> <script language="C#" runat="server"> void WriteEvent_Click(Object Src, EventArgs e) { EventLog ev = new EventLog("Application"); // Event's Source name ev.Source = "TEST"; EventLog.CreateEventSource(ev.Source, "Application"); try { ev.WriteEntry(TextBox1.Text); } catch (Exception b) { Response.Write("WriteEntry " + b.Message + "<br>"); } ev = null; } </script> <body> <form id="Form1" runat="server"> Event message: <asp:textbox id="TextBox1" runat="server" Width="233px"></asp:textbox> <asp:button id="Button1" onclick="WriteEvent_Click" runat="server" NAME="Button1" text="Write to event log"></asp:button> </form> </body> </HTML> |
3. 按F5启动此项目。
4. 在TextBox输入一些字符,然后点击Write to Event Log。
5. 在上面“现象”部分中提到的错误消息会出现。
6. 要解决此问题,在Webform1.aspx将下面这行代码注释
EventLog.CreateEventSource(ev.Source, "Application"); |
7. 重新启动此项目。
如果您非常迫切的想了解IT领域最新产品与技术信息,那么订阅至顶网技术邮件将是您的最佳途径之一。
现场直击|2021世界人工智能大会
直击5G创新地带,就在2021MWC上海
5G已至 转型当时——服务提供商如何把握转型的绝佳时机
寻找自己的Flag
华为开发者大会2020(Cloud)- 科技行者