[C#] 常用工具类——系统日志类
using System; using System.Collections.Generic; using System.Text; using System.Diagnostics; namespace Utils { /// <summary> /// <para> </para> /// 常用工具类——系统日志类 /// <para> ---------------------------------------------------</para> /// <para> WriteEventLog:写入系统日志(2个方法重载)</para> /// <para> DelEventName:删除日志事件源分类</para> /// </summary> public class EventLogHelper { #region 写入系统日志 /// <summary> /// 写入系统日志 /// </summary> /// <param name="EventName">事件源名称</param> /// <param name="LogStr">日志内容</param> public static void WriteEventLog(string EventName, string LogStr) { try { if (!EventLog.SourceExists(EventName)) { EventLog.CreateEventSource(EventName, EventName); } EventLog.WriteEntry(EventName, LogStr); } catch (Exception) { } } /// <summary> /// 写入系统日志 /// </summary> /// <param name="EventName">事件源名称</param> /// <param name="LogType">日志类型</param> /// <param name="LogStr">日志内容</param> public static void WriteEventLog(string EventName, string LogStr, EventLogEntryType LogType) { try { if (!EventLog.SourceExists(EventName)) { EventLog.CreateEventSource(EventName, EventName); } EventLog.WriteEntry(EventName, LogStr, LogType); } catch (Exception) { } } #endregion #region 删除日志事件源分类 /// <summary> /// 删除日志事件源分类 /// </summary> /// <param name="EventName">事件源名</param> /// <returns></returns> public static bool DelEventName(string EventName) { bool flag = false; try { if (EventLog.SourceExists(EventName)) { EventLog.DeleteEventSource(EventName,"."); flag = true; } } catch (Exception) { } return flag; } #endregion } }
作者:阿笨
【官方QQ一群:跟着阿笨一起玩NET(已满)】:422315558
【官方QQ二群:跟着阿笨一起玩C#(已满)】:574187616
【官方QQ三群:跟着阿笨一起玩ASP.NET(已满)】:967920586
【官方QQ四群:Asp.Net Core跨平台技术开发(可加入)】:829227829
【官方QQ五群:.NET Core跨平台开发技术(可加入)】:647639415
【网易云课堂】:https://study.163.com/provider/2544628/index.htm?share=2&shareId=2544628
【腾讯课堂】:https://abennet.ke.qq.com
【51CTO学院】:https://edu.51cto.com/sd/66c64
【微信公众号】:微信搜索:跟着阿笨一起玩NET