title: 自定义log4j2发送日志到KafkaPicture description (max. 50 words)The Tags:log4j2,kafka to provide the company's big data platform with logs for each project group, while making the project groups unaware of the changes. Did a survey only to find LOG4J2 default has the support to send the log to the Kafka function, under the surprise hurriedly looked under log4j to its realization source! found that the default implementation is synchronous blocking, if the Kafka service once hung up will block the
New Log4netmanager (name );} Else { Return New Simplelogmanager ();}}}
The code for subclass of the specific implementation interface is as follows:
/// /// Log4netmanager provides log4net-based application log operations /// Public Class Log4netmanager: ilog { Private Log4net. ilog _ log; Public Log4netmanager (String Name) {_ log = Log4net. logmanager. getlogger (name );} Public Log4netmanager (type) {_ lo
. domconfigurator (configfile = "Web. config", watch = true)]
Note: If you are using a nunit test friend, use the generated event, copy "$ (projectdir) app. config" "$ (targetpath). config"
4. Get the ilog object in the ApplicationIntroduce the log4net space in the class that requires the logger function, and add static read-only members to the class (static purpose is to use only one object, and read-only is to prevent incorrect modification)Private Static readonly ilog logger =
; } bool IsInfoEnabled { get; } bool IsWarnEnabled { get; }}
Generally, logmanager. getlogger () is used to obtain a logger. Logmanager maintains a hashtable internally, saves the newly created logger reference, and obtains its instance directly from hashtable when needed next time.
ILog log = LogManager.GetLogger(this.GetType());log.Debug("aaaaaaaaaaaaaaa");
All logger parameter settings are directly
definition of the log storage path is related to the log output format.The preceding layout output format is as follows:20:26:04, 033 [1736] Error utility [paystub]-cocould not find a part of the path
"C: \ Inetpub \ wwwroot \ testproj \ template \ paystub. xml"
4. If you want to add your diagnosis information to log4net, you must add the following code to the Web. config file:
Run the following code on the system. Web node:
Type = "system. Diagnostics. textwritertracelistener"Initializedata =
I have been using logs encapsulated by others for some time. I feel very curious when I have configured logs. Next we will record the common usage of using log4j to process logs.
As for what log4j is, I don't know what it is, and I don't think it is necessary to go too deep for the moment. I only know that it is a good choice to process logs.Game starts
References
1) official PDF document
2) Configure log4j (and details)
3) Log Level of log4j
Dependent jar package
1) log4j-api-2.0.2.jar
2) log4j
/2008/02/15/119657.aspx]
Begin to log
In every page you want to log something, add the static variable like below:Private Static readonly ilog log = logmanager. getlogger (system. reflection. methodbase. getcurrentmethod (). declaringtype );
This class has 5 levels of severity to log the operations:
Log. debug ("log something at this level ")Log. Info ("log something at this level ")Log. Warn ("log something at this level ");Log. Error ("log s
There are so many managers in ogre, just like a bureaucratic company. There are only a few officers, and a bunch of managers are still Singleton. it is a Singleton, but a public constructor. when new is applied for 1st times, this is secretly assigned to the static member ms_singleton. When new is applied for 2nd times, assert will complain, of course, this is all done by the constructor of the template base class named Singleton (typical villain behavior, see it ). there are a lot of managers,
1. Introduction of log4net
Download and introduce log4net. dll in a web project
2. Place log4net. config in the root directory of the web project.
3. Add code in application_start of Global
Log4net. config. xmlconfigurator. configureandwatch (new system. Io. fileinfo (server. mappath ("~ /") +" Log4net. config "));
4. Declare and assign values to the base page class
For example, private ilog _ logger = NULL;/// /// System Log Interface/// Public ilog Logger{Get {return _ logger ;}}
Protected ove
use the debug function of eclipse or idea.
Info: output the information that you are interested in or that is the most useful.
Warn: Some information is not an error message, but some prompts should also be given to the programmer. Similar to the code verification in eclipse, there are not error and warn (not an error, but please note that, for example, the following depressed method ).
Error: error message. It is also widely used.
Fatal: The level is relatively high. Major errors. You can stop
. Backupexpired: Backup expiration time. The Unit is day. Must be an integer. The default value is 30 days. Cycleminutes: Cycle cycle time. Unit: Minute. Must be an integer. The default value is 60 minutes.
Then, write a description document for the configuration, so that the customer will configure it.2) record logs
When the program is running, various problems are inevitable, and it is inevitable to record logs. The related code is as follows:
using System;using System.Collections.Generic;usi
Preface
For details about log4j2, refer to the previous blog.
A good thing about log4j2 is that you can use configuration file to configure log system. However, the storage location of this configuration file is quite tangled. This article describes how to change the path and name of the log4j2 configuration file.
Directory
The content of this article will answer the following questions:
1. How to generate a logevent?
2. What is the transfer of logevent?
3. How do I change the name
winform Program Use log4net 1. reference DLL 2. add log4net. config, set "always copy" 4. assemblyinfo. add [Assembly: log4net. config. xmlconfigurator (configfile = "log4net. config ", watch = true)] 5. in Code , use the following statement to record information. logger is the current class. log4net. logmanager. getlogger (system. reflection. methodbase. getcurrentmethod (). declaringtype ). info ("columnclick"); // applicable to static clas
. xml
Analysisxml. CS
Using system; using system. collections. generic; using system. LINQ; using system. text; using system. XML; using system. windows. forms; namespace clientiis {// parse the xml configuration file class analysisxml {// get the app. config value Public String getvalue (string appkey) {xmldocument xdoc = new xmldocument (); try {xdoc. load (application. startuppath + "\ app. config "); xmlnode xnode; xmlelement xelem; xnode = xdoc. selectsinglenode ("// app Settings "); xe
# Default file output is in user ' s home directory.
Java.util.logging.FileHandler.pattern =%h/java%u.log
java.util.logging.FileHandler.limit = 50000
Java.util.logging.FileHandler.count = 1
java.util.logging.FileHandler.formatter = Java.util.logging.XMLFormatter
# Limit The message that are printed on the console to INFO and above.
Java.util.logging.ConsoleHandler.level = WARNING
Java.util.logging.ConsoleHandler.formatter = Java.util.logging.SimpleFormatter
1: Rewrite the ou
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.