本文整理汇总了C#中System.Diagnostics.EventLog.Close方法的典型用法代码示例。如果您正苦于以下问题:C# EventLog.Close方法的具体用法?C# EventLog.Close怎么用?C# EventLog.Close使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Diagnostics.EventLog
的用法示例。
在下文中一共展示了EventLog.Close方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: DebugWriteLine
private void DebugWriteLine(EventLogEntryType type, string message)
{
_log = new EventLog();
_log.Source = "ApplicationLog";
_log.WriteEntry(message, type);
_log.Close();
}
示例2: CloseEventLog
private static void CloseEventLog(EventLog log)
{
try
{
log.Close();
}
catch (Win32Exception we)
{
Console.WriteLine("Error closing event log: " + we.ToString());
}
}
示例3: SqlExceptionHandling
public static void SqlExceptionHandling(SqlException sqlex, string strModule, string strMethod, string strMsg)
{
EventLog objEventLog = new EventLog();
string strApplicationName = "SLDDBLog";
objEventLog.Source = strApplicationName;
objEventLog.Log = strApplicationName;
objEventLog.WriteEntry(Environment.NewLine + "Date : " + DateTime.Now + Environment.NewLine + "Module Name : " + strModule + Environment.NewLine + "Method Name : " + strMethod + Environment.NewLine + "Exception Number : " + sqlex.ErrorCode + Environment.NewLine + "Exception Message : " + sqlex.Message + Environment.NewLine + "Additional Information : " + strMsg, EventLogEntryType.Error);
objEventLog.Close();
objEventLog.Dispose();
}
示例4: Log
public static void Log(Exception ex)
{
var log = new EventLog
{
Source = "Xuat_Nhap_Excel/BizService"
};
log.WriteEntry(string.Concat(new object[] { ex.Message, Environment.NewLine,
ex.Source, Environment.NewLine,
ex.StackTrace,
ex.TargetSite,
ex.InnerException }), EventLogEntryType.Error, 100);
log.Close();
}
示例5: Log
private void Log(string message, int eventId, EventLogEntryType type)
{
try
{
InitSource();
EventLog ev = new EventLog(LogName, Environment.MachineName, Source);
ev.WriteEntry(message, type, eventId);
ev.Close();
}
catch
{
}
}
示例6: OnLog
/// <summary>
/// Called when [log].
/// </summary>
/// <param name="type">The type.</param>
/// <param name="message">The message.</param>
public static void OnLog(EventLogEntryType type, string message)
{
LogHandler handler = Log;
if (handler != null) handler(type, "(T"+ Thread.CurrentThread.ManagedThreadId +") " + message);
if (type == EventLogEntryType.Information) return;
try
{
var log = new EventLog { Log = "Application", Source = "TS3-Bot" };
log.WriteEntry(message, type);
log.Close();
}
catch
{ }
}
示例7: WriteEventLog
private static void WriteEventLog(string event_source, string content, EventLogEntryType type)
{
try
{
if (!EventLog.SourceExists(event_source))
{
EventLog.CreateEventSource(event_source, event_source);
}
using (EventLog elog = new EventLog())
{
elog.Log = event_source;
elog.Source = event_source;
elog.WriteEntry(content, type);
elog.Close();
}
}
catch { }
}
示例8: ErrorLog
public static void ErrorLog(string LogStr, EventLogEntryType Type)
{
try
{
System.Security.Principal.WindowsImpersonationContext wic = WindowsIdentity.Impersonate(IntPtr.Zero);
var El = new EventLog();
if (EventLog.SourceExists(ErrorLogname) == false)
EventLog.CreateEventSource(ErrorLogname, ErrorLogname);
El.Source = ErrorLogname;
El.WriteEntry(LogStr, Type);
El.Close();
wic.Undo();
}
catch (Exception Ex87)
{
WriteTextLog(Ex87.Message + "\r" + LogStr);
}
}
示例9: ErrorLog
public static void ErrorLog(string LogStr, EventLogEntryType Type)
{
try
{
WindowsImpersonationContext wic = WindowsIdentity.Impersonate(IntPtr.Zero);
var El = new EventLog();
if (EventLog.SourceExists("CIMBTimeSheet") == false)
EventLog.CreateEventSource("CIMBTimeSheet", "CIMBTimeSheet");
El.Source = "CIMBTimeSheet";
El.WriteEntry(LogStr, Type);
El.Close();
wic.Undo();
}
catch (Exception Ex87)
{
WriteTextLog(Ex87.Message + "\r" + LogStr);
}
}
示例10: WriteEventLog
internal static void WriteEventLog(string content, EventLogEntryType type)
{
const string event_source = "Soho.Utility.Logger";
const string event_name = "Soho.Utility.Logger_Exception";
try
{
if (!EventLog.SourceExists(event_source))
{
EventLog.CreateEventSource(event_source, event_name);
}
using (EventLog elog = new EventLog())
{
elog.Log = event_name;
elog.Source = event_source;
elog.WriteEntry(content, type);
elog.Close();
}
}
catch { }
}
示例11: WriteEventLog
public static void WriteEventLog(Exception exc, string message = "", string eventLogName = Constants.EventLogName)
{
try
{
if (EventLog.SourceExists(Constants.EventLogName) == true)
{
EventLog myLog = new EventLog();
myLog.Source = Constants.EventLogName;
myLog.WriteEntry(string.Format("Dev Message {0} ErrorMessage: {1} \n\nStackTrace: {2}", message, exc.Message, exc.StackTrace), EventLogEntryType.Error);
myLog.Close();
}
}
catch (Exception ex)
{
}
}
示例12: Log
public static void Log(string message, EventLogEntryType eventType, EventID eventID)
{
const string applicationName = "CIWaterNetService";
// Create an instance of EventLog
EventLog eventLog = new EventLog();
// Check if the event source exists. If not create it.
if (!System.Diagnostics.EventLog.SourceExists(applicationName))
{
EventLog.CreateEventSource(applicationName, "Application");
}
// Set the source name for writing log entries.
eventLog.Source = applicationName;
// Write an entry to the event log.
eventLog.WriteEntry(message, eventType, (int)eventID);
// Close the Event Log
eventLog.Close();
}
示例13: ReadEventLog
public string ReadEventLog(EventLog eventLog, int logcount = 1000)
{
var count = logcount;
var total = eventLog.Entries.Count - 1;
var sb = new StringBuilder();
while (count-- > 0)
{
var entry = eventLog.Entries[total--];
sb.AppendFormat("消息:{0};时间:{1};来源:{2};类型:{3};"
, entry.Message
, entry.TimeGenerated.ToString("yyyy-MM-dd HH:mm:ss.fff")
, entry.Source
, entry.EntryType.ToString()
);
sb.AppendLine();
}
eventLog.Close();
return sb.ToString();
}
示例14: WriteEvent
public void WriteEvent(string strMessage, EventLogEntryType type)
{
if (!EventLog.SourceExists(this._sourece))
EventLog.CreateEventSource(this._sourece, this._eventName);
EventLog eventLog = new EventLog();
eventLog.Log = this._eventName;
eventLog.Source = this._sourece;
try
{
eventLog.WriteEntry(strMessage, type);
}
catch (Exception ex)
{
eventLog.Clear();
this.WriteEvent("日志文件已满,执行清除操作!", EventLogEntryType.Warning);
eventLog.WriteEntry(strMessage, type);
}
finally
{
eventLog.Close();
eventLog.Dispose();
}
}
示例15: viewLog
public string viewLog(string log,int maxNum)
{
String retVal = "";
//if(EventLog.SourceExists(log))
try
{
EventLog aLog = new EventLog();
aLog.Log = log;
aLog.MachineName = ".";
//foreach (EventLogEntry entry in aLog.Entries)
EventLogEntry entry;
for(int i=aLog.Entries.Count-1;(i>0 && (i > aLog.Entries.Count-1 - maxNum));i--)
{
entry = aLog.Entries[i];
retVal += " " + entry.TimeGenerated.ToString().Replace(":","#C#") + ": " + entry.EntryType + " - " + entry.Source + "\n" + entry.Message+"\n";
}
aLog.Close();
}
catch (Exception e){
}
return retVal;
}