[Original] Use .NET writes in Windows2000

xiaoxiao2021-03-06  56

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 /// public class logutility {public enum event {/// Major error Event_ERROR, / // Operation failed General Information Event_information, /// Valid, successful operation Event_suCcessAudit, /// Warning Event_warning,}

Private static textwritertracelistener listner = NULL;

///

/// Structure function /// public logutility () {} /// login ID /// Screen ID /// Warning level /// log information 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 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 /// /// Login ID /// screen ID < / param> /// Error level /// log information /// output log information 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.

转载请注明原文地址:https://www.9cbs.com/read-113841.html

New Post(0)