Author:. Bluesky35 (blue) 1 See first column VB6.0 using other techniques to access the registry, create HKEY_LOCAL_MACHINE, / SYSTEM / CurrentControlSet / Services / Eventlog / Eventlog2 / Eventlog2 key, and writes EventMessageFile, value is C: / Winnt / Microsoft.Net / Framework / V1.1.4322 / EVENTLOGMESSAGES.DLL2. In C # .net uses the following code writes the log // Output log's classusing system; use system.diagnostics; use system.text;
Namespace CorePlus.framework.utility {/// /// Write logs Class /// summary> public class logutility {public enum event {/// Major error summary> Event_ERROR, / // Operation failed /// General Information Summary> Event_information, /// Valid, successful operation summary> Event_suCcessAudit, /// Warning summary> Event_warning,}
Private static textwritertracelistener listner = NULL;
/// /// Structure function /// summary> public logutility () {} /// login ID param> /// Screen ID param> /// Warning level param> /// log information param> public static void logging (String Loginid, String screenID, EVENT Level, String Message) {// Variable Definition StringBuilder OutputMessage = NULL; // Output information String TargetleVelstring = Null; EventLoGentryType EventType = New EventLoGENTRYTYPE ();
switch (level) {case EVENT.EVENT_ERROR: Eventtype = EventLogEntryType.Error; break; case EVENT.EVENT_FAILUREAUDIT: Eventtype = EventLogEntryType.FailureAudit; break; case EVENT.EVENT_INFORMATION: Eventtype = EventLogEntryType.Information; break; case EVENT.EVENT_SUCCESSAUDIT: Eventtype = EventLogEntryType.SuccessAudit; break; case EVENT.EVENT_WARNING: Eventtype = EventLogEntryType.Warning; break;} // log information is split outputMessage = MakeMessage (loginID, screenID, targetLevelString, message);
// Write logs logging (eventtype, outputMessage.tostring ());
/// / // 向 日 管理 管理 管理 管理>>>>>>>>>>>>>>>>>>>>> information output param> private static void logging (EventLogEntryType level, string message) {// variables defined string logName = null; // log name string machineName = null; // machine name string sourceName = null; // SourceName EventLog EventLog = null; // EventLog
Logname = "EventLog2"; // Log Name Machinename = "."; // Machine name SourceName = "EventLog2"; // SourceName
EventLog = New EventLog (Logname, Machinename, SourceName); EventLog.WriteEntry (Message, Level); EventLog = NULL;}
/// /// Log finally flattened /// summary> /// Login ID param> /// screen ID < / param> /// Error level param> /// log information param> /// output log information returns > private static StringBuilder MakeMessage (string loginID, string screenID, string levelString, string message) {// variables defined StringBuilder retMessage = new StringBuilder (); retMessage.Append ( "login ID []"); retMessage.Append (loginID); RetMessage.Append ("/ n [screen ID]"); RetMessage.Append (ScreenID); RetMessage.Append ("/ N [Error Level]); RetMessage.Append (LevelString); RetMessage.Append (" / N 【 Error message] / n "); retMessage.Append (Message);
return retMessage;}}} // log the output FORM private void button1_Click (object sender, System.EventArgs e) {LogUtility.Logging ( "bbbbbb", "22222222", LogUtility.EVENT.EVENT_ERROR, "3333333");} Open the log manager after running the program ~~~~~~~~~ How? Not bad, huh, huh.