


A detailed introduction to Log4net logging and a detailed introduction to the application code
This article mainly introduces the detailed introduction of Log4net logging and related application information. Friends who need it can refer to
Log4net log
Summary :
Log4net is a tool that helps programmers output log information to various targets (console, file, database, etc.). The log is the black box of the program. You can use the log to view the running process of the system and discover system problems. The function of logs: record the steps, successes and failures of the running process, record key data, and then analyze system problems. Because for websites, exception information cannot be displayed to users, and exception information can only be recorded in the log. When there is a problem with the website, the developer knows the problem by looking at the logs.
1. How to configure the Log4net environment
1. Add the "Application Configuration File" (App.config);
2. Add configuration in App.config or Web.config:
<log4net> <!-- Define some output appenders --> <appendernameappendername="RollingLogFileAppender"type="log4net.Appender.RollingFileAppender"> <file value="test.txt"/> <appendToFilevalueappendToFilevalue="true"/> <maxSizeRollBackupsvaluemaxSizeRollBackupsvalue="10"/> <maximumFileSizevaluemaximumFileSizevalue="1024KB"/> <rollingStylevaluerollingStylevalue="Size"/> <staticLogFileNamevaluestaticLogFileNamevalue="true"/> <layouttypelayouttype="log4net.Layout.PatternLayout"> <conversionPattern value="%date[%thread] %-5level %logger - %message%newline"/> </layout> </appender> <root> <level value="DEBUG"/> <appender-refrefappender-refref="RollingLogFileAppender"/> </root> </log4net>
3. Add Log4net.dll reference;
4. Set the property "Copy to output directory" of log4net.config to "Always copy";
5. Initialization:
Add log4net.Config.XmlConfigurator.Configure at the beginning of the program () Let the current Log4net work;
6. Write LonManager.GetLogger(typeof(Program)).Debug("information"); where you want to print the log.
Pass the name of the log class to be recorded through LonManager.GetLogger() to obtain the class ILog, so that in the log file you will know which class outputs the log, and then call the Debug method to output the message. Because logs need to be printed in more than one place within a class, ILog is generally declared as a static field.
7. Use the Ilog.Error method to output error information. The second parameter can pass an Exception object. Log.Error("****Error"+ex);
2. Log4NetDemo
<pre code_snippet_id="2146508" snippet_file_name="blog_20170123_2_6827063" name="code" class="csharp">namespace Log4NetDemo { class Program { static void Main(string[] args) { //使用log4net记录日志。 log4net.Config.XmlConfigurator.Configure(); ILog logWriter =log4net.LogManager.GetLogger("Test"); logWriter.Info("消息"); logWriter.Warn("警告"); logWriter.Error("异常"); logWriter.Fatal("错误"); } }}
三、Appender
可以在配置文件中使用Log4net的Appender方法进行优化;<strong><span> <img i0jbqkfcma='=/dissolve/70/gravity/Center" alt=""'> 更多内容,推荐阅读: <a>http://www.php.cn/;/a> 以上是我对Log4net日志记录的简单理解,请路过的大鸟指点。</a></span></strong> <p></p>
The above is the detailed content of A detailed introduction to Log4net logging and a detailed introduction to the application code. For more information, please follow other related articles on the PHP Chinese website!

Start Spring using IntelliJIDEAUltimate version...

When using MyBatis-Plus or other ORM frameworks for database operations, it is often necessary to construct query conditions based on the attribute name of the entity class. If you manually every time...

Java...

How does the Redis caching solution realize the requirements of product ranking list? During the development process, we often need to deal with the requirements of rankings, such as displaying a...

Conversion of Java Objects and Arrays: In-depth discussion of the risks and correct methods of cast type conversion Many Java beginners will encounter the conversion of an object into an array...

Solutions to convert names to numbers to implement sorting In many application scenarios, users may need to sort in groups, especially in one...

Detailed explanation of the design of SKU and SPU tables on e-commerce platforms This article will discuss the database design issues of SKU and SPU in e-commerce platforms, especially how to deal with user-defined sales...

How to set the SpringBoot project default run configuration list in Idea using IntelliJ...


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version
Recommended: Win version, supports code prompts!

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download
The most popular open source editor