This article is a mirror article of machine translation, please click here to jump to the original article.

View: 19099|Reply: 1

[Source] log4net's ConversionPattern parameter

[Copy link]
Posted on 4/15/2017 10:50:59 AM | | |

Log4net recommends using only four levels, with the highest to lowest priority being ERROR, WARN, INFO, and DEBUG
#这里定义能显示到的最低级别, if you define it to the INFO level, you will not see the DEBUG level information~!
log4j.rootLogger=DEBUG
#将DAO层log记录到DAOLog, in allLog
log4j.logger.DAO=DEBUG,A2,A4
#将逻辑层log记录到BusinessLog, in allLog
log4j.logger.Businesslog=DEBUG,A3,A4

#A1 - Print to the screen
log4j.appender.A1=org.apache.log4j.ConsoleAppender
log4j.appender.A1.layout=org.apache.log4j.PatternLayout
log4j.appender.A1.layout.ConversionPattern=%-5p [%t] %37c %3x - %m%n

#A2 - printed into a file DAOLog - specifically for the DAO layer
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.file=DAOLog
log4j.appender.A2.DatePattern='.' yyyy-MM-dd
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

#A3 -- Print to file BusinessLog -- Specifically record Log information for logical processing layer services
log4j.appender.A3=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A3.file=BusinessLog
log4j.appender.A3.DatePattern='.' yyyy-MM-dd
log4j.appender.A3.layout=org.apache.log4j.PatternLayout
log4j.appender.A3.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

#A4 - print into file alllog - record all log information
log4j.appender.A4=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A4.file=alllog
log4j.appender.A4.DatePattern='.' yyyy-MM-dd
log4j.appender.A4.layout=org.apache.log4j.PatternLayout
log4j.appender.A4.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

#Appender的使用
log4j.appender.A2=org.apache.log4j.DailyRollingFileAppender
log4j.appender.A2.file=demo
log4j.appender.A2.DatePattern='.' yyyy-MM-dd
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=%m%n

#Layout的配置
log4j.appender.A2.layout=org.apache.log4j.PatternLayout
log4j.appender.A2.layout.ConversionPattern=[%-5p] %d{yyyy-MM-dd HH:mm:ss,SSS} method:%l%n%m%n

ConversionPatternparameter
Format Name Meaning
%c The full name of the class to which the output log information belongs
%d outputs the date or time of the log time point, the default format is ISO8601, or you can specify the format after it, for example: %d{yyy-MM-dd HH:mm:ss }, and the output is similar: 2002-10-18- 22:10:28
%f The class name of the class to which the output log information belongs
%l The location where the output log event occurs, that is, the statement that outputs the log information is on the line of the class it is in
%m outputs the information specified in the code, such as the message in log(message).
%n outputs a carriage return newline, "rn" for Windows and "n" for Unix
%p output priority, i.e. DEBUG, INFO, WARN, ERROR, FATAL. If the output is called debug(), then DEBUG, and so on
%r outputs the number of milliseconds it took from the start of the application to the output of the log information
%t outputs the name of the thread that generated the log event

#1 defines two outputs
log4j.rootLogger = INFO, A1, A2,A3

#2 Define the A1 output to the controller
log4j.appender.A1 = org.apache.log4j.ConsoleAppender
#3 Define the layout mode of A1 as PatternLayout
log4j.appender.A1.layout = org.apache.log4j.PatternLayout
#4 Define the output format of A1
log4j.appender.A1.layout.ConversionPattern = %-4r [%t] %-5p %c - %m%n

#5 Define A2 output to file
log4j.appender.A2 = org.apache.log4j.RollingFileAppender
#6 Define which file A2 wants to output to
log4j.appender.A2.File = F:nepalonclassesexample3.log
#7 Define the maximum length of the output file for A2
log4j.appender.A2.MaxFileSize = 1KB
#8 Define the number of backup files for A2
log4j.appender.A2.MaxBackupIndex = 3
#9 Define the layout pattern of A2 as PatternLayout
log4j.appender.A2.layout = org.apache.log4j.PatternLayout
#10 Define the output format of A2
log4j.appender.A2.layout.ConversionPattern = %d{yyyy-MM-dd hh:mm:ss}:%p %t %c - %m%n




Previous:The class Form1 can be designed, but it is not the first class in the file. Visual Studio requires designers to use the document
Next:Alibaba Cloud: Windows SMB/RDP remote command execution vulnerability repair tutorial
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com