imports system.diagnosticsimports system.configuration.installimports 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 classvisual 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); } }}
<%@ 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>
eventlog.createeventsource(ev.source, "application")
新闻热点
疑难解答
图片精选