Logger to be efficient, simple. No more nonsense.
GitHub Address Https://github.com/goldli/logger
The logger used System.logger as namespace in this paper;
I. Description of the Object
There are two types of objects in the DLL logger
1. Logger log Output Control class. Responsible for enabling and disabling the logging feature.
2. Log Logging class.
Second, enable/disable log
Logger.Instance.Start ();
Logger.Instance.Stop (). Dispose ();
The logger itself inherits from the IDisposable interface. You can call Dispose after stop to release resources.
Third, record the log
A log object needs to be instantiated: Use Logger.Instance.GetLog ("Log folder name");
Ways to log logs
1, the general wording Writelog ("Log Content");
2, with sequential serial number of the way Write ("Log Content", the starting sequence number);
If the starting sequence number is 0, the log content will be processed +1.
If the starting sequence number is not 0, the Write method begins with +1 processing with this sequence number
Iv. Log directory structure
The log class itself has the folder property and the FileName property
Folder can be used to refer to the location where the write log is saved, and the log directory under the same directory as the main program EXE that is currently being invoked, if specified.
FileName is not a log file name. Instead, the name of the folder where the log file resides. The specific log files are named in hours.
The final file directory structure is
X:\log\{filename}\{yyyy-mm-dd}\{hh}.log
Or
X:\{filename}\{yyyy-mm-dd}\{hh}.log
V. Examples
1. For general examples, please refer to
2. Multithreading Example
2.1 Declaring Logger objects
Internal Logger Logger = logger.instance;
2.2 Passing logger to the thread object
var task1 = new Task
{
Config = config,
Logger = Logger
};
2.3 Creating Threads
Logger.start ();
_patrolor = new Thread (Tick) {isbackground = true};
_patrolor. Start (TASK1);
2.4 Create Log in thread
Class Task
{
protected override void Execute (Task Task)
{
_logger = task. Logger.getlog ("Alertservice");
_logger. Writelog ("Begin");
Do (Task);
_logger. Writelog ("End");
}
}
VI. matters of caution
We use it for a variety of data during thread processing. It is important to remember that the data used during threading is passed in from the object state parameter. Rather than the class from which the process is handled
Simplified version available for multi-threaded logger