A class that handles information and, add information, error, and warning to the Event View class
Using system.id; using system.diagnostics; using system.configuration;
Namespace Common {///
EventLogname = "EventLogname"; System.Diagnostics.Eventlog ObjeventLog = New EventLog (); ObjeventLog.Source = "EventLogname";
IF (! system.diagnostics.eventlog.sourceexists (EventLogname)) {system.diagnostics.eventlog.createeventsource (EventLogname, EventLogname);
Try {// Value from the app.config file // If you are info, add any information // if Error, then ERROR load only, and warning information // If Warn, Only EVENT VIEW is loaded with only an error message traceconfig = configurationSettings.appsettings ["trace mode"];} catch {traceConfig = "info";}
Try {IF (traceConfig.toupper () == "info") {if (erroType == "e") {ObjeventLog.writeEntry (system.datetime.now.tostring () " errorMessage, EventLoGentryType.Error); WriteLogToFile (System.DateTime.Now.ToString () "" ErrorMessage);} else if (ErrorType == "W") {objEventLog.WriteEntry (System.DateTime.Now.ToString () "" ErrorMessage, EventLogEntryType .Warning);} else if (ErrorType == "I") {ObjeventLog.writeEntry () " ErrorMessage, EventLoGentrytype.information);}} // Info else IF (TraceConfig. ToUpper () == "WARNING") {if (ErrorType == "E") {objEventLog.WriteEntry (System.DateTime.Now.ToString () "" ErrorMessage, EventLogEntryType.Error); WriteLogToFile (System.DateTime. Now.toString () " ErrorMessage);} else if (ErrorTyPe ==" W ") {ObjeventLog.writeEntry (System.Datetime.now.toString () " ErrorMessage, Eventlogentr Ytype.warning);}} // Warning
else if (TraceConfig.ToUpper () == "ERROR") {if (ErrorType == "E") {objEventLog.WriteEntry (System.DateTime.Now.ToString () "" ErrorMessage, EventLogEntryType.Error); WriteLogToFile (System.datetime.now.tostring () " errorMessage);}} // error
Else {Objeventlog.writentry (System.Datetime.now.Tostring () " ErrorMessage, EventLoGentrytype.Error);} // try}} ///
String currentpath = logfilepath; DirectoryInfo Di = New DirectoryInfo (CURRENTPATH);
IF (di.exists == true) {currentpath = currentpath "//" Machinename; di = new DirectoryInfo (CurrentPath); if (di.exists == true) {// do nothing} else {di.create }
CurrentPath = CURRENTPATH "//" ApplicationID; Di = New DirectoryInfo (CURRENTPATH); if (di.exists == true) {// do nothing} else {di.create ();}
CurrentPath = CURRENTPATH "//" "Error.txt"; streamwriter stw = new streamwriter (currentpath, false); stw.writeline (system.datetime.now.tostring () " errorMessage); stw.close );}} Catch {// do nothing}}
} // Class logs
}