WriteAppEventLog. cs /**//********************************** **********************************
Created: 2006/03/30
Created: 30: 3: 2006
File ext: cs
Author: xuzhong
Purpose: Write logs to application logs
**************************************** *****************************/
Using System;
Namespace XZSoftware. App. ZhengJun
{
Public class WriteEventLog
{
Public WriteEventLog ()
{
}
Public static int Main (string [] args)
{
Int argsLength = args. Length;
If (argsLength! = 4)
{
Purging ();
Return 1;
}
Else
{
String source = args [0];
String message = args [1];
String type = args [2];
String id = args [3];
Try
{
System. Diagnostics. EventLog. WriteEntry (
Source, message, GetEventType (type), int. Parse (id ));
Return 0;
} Catch
{
Return-1;
}
}
}
Public static System. Diagnostics. EventLogEntryType GetEventType (string type)
{
Switch (type. ToLower ())
{
Case "error ":
Return System. Diagnostics. EventLogEntryType. Error;
Case "warning ":
Return System. Diagnostics. EventLogEntryType. Warning;
Case "failureaudit ":
Return System. Diagnostics. EventLogEntryType. FailureAudit;
Case "information ":
Return System. Diagnostics. EventLogEntryType. Information;
Case "successaudit ":
Return System. Diagnostics. EventLogEntryType. SuccessAudit;
Default:
Return System. Diagnostics. EventLogEntryType. Error;
}
}
Public static void Purging ()
{
Console. WriteLine ("");
Console. WriteLine ("");
Console. writeLine ("************************************* *******************************");
Console. WriteLine ("created: 2006/03/30 ");
Console. WriteLine ("created: 30: 3: 2006 ");
Console. WriteLine ("file ext: cs ");
Console. WriteLine ("author: xuzhong ");
Console. WriteLine ("");
Console. WriteLine ("purpose: Write logs to application logs ");
Console. writeLine ("************************************* ********************************");
Console. WriteLine ("");
Console. WriteLine ("");
Console. WriteLine ("WriteAppEventLog.exe <source> <message> <type> <id> ");
Console. WriteLine ("source: source ");
Console. WriteLine ("message: content information ");
Console. WriteLine ("type: Log type (Error | Warning | Information | SuccessAudit | FailureAudit )");
Console. WriteLine ("id: ID of the error ");
Console. WriteLine ("");
Console. Write ("Sample :");
Console. WriteLine ("WriteAppEventLog.exe \" My_Application \ "\" This is a test. \ "\" Error \ "\" 1000 \"");
}
}
}
Build. batcsc/t: exe *. cs
What can I do?