The world's largest supply platform for sources of shortages and hard-to-find parts

Log4Net Stores logs

Published Time: 2022-08-20 17:17:47
In the development of upper computer, log recording is indispensable, we can do log analysis and error tracking through log recording.

Beginners will use TXT text writing to achieve log saving, but text writing is not thread safe, when there are multiple threads writing to the log, there will be some problems. Log4net library is. The next great open source logging component in.NET is a tool that helps developers export logging information to a variety of targets (consoles, files, databases, etc.). In this section, the open-source component Log4Net is used to store the text of ERROR information. In combination with SQLite database, log INFO information is stored in the database for subsequent query.


SQLite store


The advantage of storing log information in the database is that it is easy for users to query logs through the interface. The open source free database SQLite is used here. Other relational databases, such as SQLServer and mysql, have the same principle, and the specific steps are as follows:


Create databases and tables


Use SQLiteStudio software to create a database, named Log4NetSQLite, execute the following script to create a Log table:

BufferSize: When the number of log cache writes is set to 0, write to the database immediately as long as there is one


ConnectionString: SQLite points to the absolute path of the database file


Add an Info method to the LogHelper class like this:


More Products Hot Selling

MT29F4G08ABADAH4-IT:D
Memory IC
MT29F4G08ABADAH4-IT:D
4Gb, 8Gb, 16Gb: x8, x16 NAND Flash Memory Features MT29F4G08ABADAH4, MT29F4G08ABADAWP, MT29F4G08ABBDAH4, MT29F4G08ABBDAHC, MT29F4G16ABADAH4, MT29F4G16ABADAWP, MT29F4G16ABBDAH4, MT29F4G16ABBDAHC, MT29F8G08ADADAH4, MT29F8G08ADBDAH4, MT29F8G16ADADAH4, MT29F8G16ADBDAH4, MT29F16G08AJADAWP
MT29F2G08ABAEAWP:E
Memory IC
MT29F2G08ABAEAWP:E
2Gb: x8, x16 NAND Flash Memory Features
LDC1101DRCR
Data Acquisition - ADCs/DACs - Special Purpose
LDC1101DRCR
LDC1101 1.8V High Resolution, High Speed Inductance to Digital Converter
TCAN1042GVDRBRQ1
Interface - Drivers, Receivers, Transceivers
TCAN1042GVDRBRQ1
TCAN1042-Q1 Automotive Fault Protected CAN Transceiver with CAN FD CAN 5Mbps Normal/Standby 5V Automotive 8-Pin VSON EP T/R
MAX4651ESE-T
Interface - Analog Switches
MAX4651ESE-T
Analog Switch ICs Low-Voltage, 4 Ohm, Quad, SPST, CMOS Analog Switches,DC 22+
TMP114AIYMTR
Temperature Sensors - Analog and Digital Output
TMP114AIYMTR
TMP114 Ultra-Thin, 1.2-V to 1.8-V Supply, High Accuracy Digital Temperature Sensor with I2C Interface
LM74700QDBVRQ1
PMIC - OR Controllers, Ideal Diodes
LM74700QDBVRQ1
LM74700-Q1 Low IQ Reverse Battery Protection Ideal Diode Controller

Recommended Parts