C# method to implement custom windows system logs
This article describes the method of implementing custom Windows system logs in C#. Share it for your reference. The specific implementation method is as follows:
using System; using ; using ; using ; using ; namespace ConsoleApp { /// <summary> /// System log /// </summary> public class PackSystemEventLog { /// <summary> /// error message /// </summary> private static string ErrorInfo { get; set; } /// <summary> /// Create system event log classification /// </summary> /// <param name="eventSourceName">Register event source (for example, this log comes from a certain application)</param> /// <param name="logName">Login name (name displayed by event list)</param> /// <returns></returns> public static bool CreateSystemEventLogCategory(string eventSourceName, string logName) { bool createResult = false; try { if (!(eventSourceName)) { (eventSourceName, logName); } createResult = true; } catch (Exception ex) { createResult = false; ErrorInfo = ; } return createResult; } /// <summary> /// Delete the system event log classification /// </summary> /// <param name="eventSource">EventName Event Source</param> /// <returns></returns> public static bool RemoveSystemEventSourceCategory(string eventSource) { bool createResult = false; try { if ((eventSource)) { (eventSource, "."); } createResult = true; } catch (Exception ex) { createResult = false; ErrorInfo = ; } return createResult; } /// <summary> /// Write logs to system logs /// </summary> /// <param name="eventSource">Event Source</param> /// <param name="msg">Write log information</param> /// <param name="type">Log text classification (warning, information, error)</param> /// <returns></returns> public static bool WriteSystemEventLog(string eventSource, string msg, EventLogEntryType type) { bool writeResult = false; try { if (!(eventSource)) { writeResult = false; ErrorInfo = "Log classification does not exist!"; } else { (eventSource, msg, type); writeResult = true; } } catch (Exception ex) { writeResult = false; ErrorInfo = ; } return writeResult; } /// <summary> /// Delete the logName in the event source (it seems to have deleted all logs of this category) /// </summary> /// <param name="eventSource"></param> /// <param name="logName"></param> /// <returns></returns> public static bool RemoveSystemEventLog(string eventSource, string logName) { bool removeResult = false; try { if (!(eventSource)) { removeResult = false; ErrorInfo = "Log classification does not exist!"; } else { (logName); removeResult = true; } } catch (Exception ex) { removeResult = false; ErrorInfo = ; } return removeResult; } /// <summary> /// Get error message /// </summary> /// <returns></returns> public static string GetErrorMessage() { return ErrorInfo; } } }
I hope this article will be helpful to everyone's C# programming.
Related Articles
Convert C# string string, memory stream MemoryStream and bit array byte[]
This article mainly introduces the method of converting string string, memory stream MemoryStream and bit array byte[]. If you need it, please refer to it.2016-05-05A brief discussion on the difference between C# non-mode form show() and mode form showdialog()
Below, the editor will give you a brief article on the difference between C# non-mode form show() and mode form showdialog(). The editor thinks it is quite good, so I will share it with you now and give you a reference. Let's take a look with the editor2016-07-07Summary of C# TreeView control usage skills
This article mainly introduces a summary of the skills of using C# TreeView controls. TreeView controls are also used frequently in form applications. When we use TreeView, we generally display resources in a layered manner, similar to the concave representation of trees in data structures.2022-08-08Summary of several methods of executing Javascript code in C#
This article mainly summarizes and introduces several methods of executing Javascript code in C#. Friends who need it can come and refer to it. I hope it will be helpful to you.2014-01-01C# thread queue usage example analysis
This article mainly introduces the usage of C# thread queues, and analyzes the operation techniques of C# thread queues in an example form, which has certain reference value. Friends who need it can refer to it.2015-09-09C# commissioned detailed explanation and example sharing
This article discusses the delegation in C# in detail, lists its main implementation methods, and analyzes its benefits at the design and coding levels. Finally, it will discuss its security and execution efficiency, etc., and of course there are implementation examples.2014-03-03MVVM simplified Messager class instance code
This article mainly introduces relevant materials about the simplified Messager class of MVVM. The article introduces the sample code in detail, which has certain reference learning value for everyone's study or work. Friends who need it, please learn with the editor below.2018-06-06C# Example code for obtaining computer hardware information
This article mainly introduces sample code for obtaining computer hardware information in C# to help everyone better understand and learn C#. Interested friends can learn about it.2020-10-10Detailed explanation of Unity's implementation of batch Build packaging
Generally speaking, if the project is PC or Android or IOS, there will be no need for batch Build packaging, but if the project is WebGL, you may encounter such needs. This article mainly introduces how to implement Build batch packaging in Unity. Friends who need it can refer to it.2021-12-12C# Implementation method for determining whether time periods intersect
This article mainly introduces the relevant information on the implementation method of C# to determine whether time periods intersect. I hope this article can help you and enable you to implement such functions. Friends who need it can refer to it.2017-10-10