|
using System;
using System.Diagnostics;
using System.Text;
namespace OLEExample
{
public class ClsExample
{
private bool IsExist(string strLogName)
{
bool Reasult = false;
if (System.Diagnostics.EventLog.SourceExists(strLogName)) return Reasult = true;
return Reasult;
}
public bool CreateLog(string strLogName)
{
bool Reasult = false;
try
{
if (!this.IsExist(strLogName))
{
System.Diagnostics.EventLog.CreateEventSource(strLogName, strLogName);
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
SQLEventLog.Source = strLogName;
SQLEventLog.Log = strLogName;
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry("The " + strLogName + " was successfully initialize component.", EventLogEntryType.Information);
Reasult = true;
}
}
catch
{
Reasult = false;
}
return Reasult;
}
#region "Windows event log writer"
public void Write_ERROR_EventLog(string strLogName
, string strSource
, string strErrDetail)
{
if (this.IsExist(strLogName))
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
try
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource)
+ Convert.ToString(strErrDetail), EventLogEntryType.Error);
}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("ERROR: ")
+ Convert.ToString(ex.Message), EventLogEntryType.Error);
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}
}
public void Write_WARNING_EventLog(string strLogName
, string strSource
, string strErrDetail)
{
if (this.IsExist(strLogName))
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
try
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource)
+ Convert.ToString(strErrDetail), EventLogEntryType.Warning);
}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("WARNING: ")
+ Convert.ToString(ex.Message), EventLogEntryType.Warning);
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}
}
public void Write_INFO_EventLog(string strLogName
, string strSource
, string strErrDetail)
{
if (this.IsExist(strLogName))
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
try
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource)
+ Convert.ToString(strErrDetail), EventLogEntryType.Information);
}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("INFORMATION: ")
+ Convert.ToString(ex.Message), EventLogEntryType.Information);
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}
}
public void Write_FAILUR_EventLog(string strLogName
, string strSource
, string strErrDetail)
{
if (this.IsExist(strLogName))
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
try
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource)
+ Convert.ToString(strErrDetail), EventLogEntryType.FailureAudit );
}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("FAILUR: ")
+ Convert.ToString(ex.Message), EventLogEntryType.FailureAudit );
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}
}
public void Write_SUCCESS_EventLog(string strLogName
, string strSource
, string strErrDetail)
{
if (this.IsExist(strLogName))
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
try
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource)
+ Convert.ToString(strErrDetail), EventLogEntryType.SuccessAudit );
}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("FAILUR: ")
+ Convert.ToString(ex.Message), EventLogEntryType.SuccessAudit );
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}
}
#endregion
public void Write_AUTHOR_EventLog(string strLogName
, string strSource
, string strErrDetail)
{
if (this.IsExist(strLogName))
{
System.Diagnostics.EventLog SQLEventLog = new System.Diagnostics.EventLog();
try
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString(strSource)
+ Convert.ToString(strErrDetail), EventLogEntryType.Information);
}
catch (Exception ex)
{
SQLEventLog.Source = strLogName;
SQLEventLog.WriteEntry(Convert.ToString("INFORMATION: ")
+ Convert.ToString(ex.Message), EventLogEntryType.Information);
}
finally
{
SQLEventLog.Dispose();
SQLEventLog = null;
}
}
}
public string GetAuthor()
{ return "Md. Marufuzzaman"; }
}
}
|
By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.
If a file you wish to view isn't highlighted, and is a text file (not binary), please
let us know and we'll add colourisation support for it.