"), ex);}finally{ //ifjuliisused,shutjulidown*after* theservershutsdown//sologmessages aren ' tlostlogmanagerlogmanager= Logmanager.getlogmanager ();if (logmanagerinstanceof Classloaderlogmanager) { (ClasslOaderlogmanager) logmanager). Shutdown (); }}}} " hook program because it is the inner class of Catalina, so it can call related methods in the Catalina class. It calls the Stop method to close the related service component . The hook is registe
component of the implementation is a custom logmanager that can get different web apps (and different class loader) running in Tomcat. He supports configuring a separate log configuration for the app. When a web app is uninstalled from within, it gets a notification from Tomcat so that the classes he refers to can be purged and avoid memory leaks.Tomcat-native.tar.gz inside is the Tomcat local library.Tool-wrapper.bat Tool Wrapper ScriptVersion.bat i
is Infologger's record"); Infologger.setlevel (level.info);//set to low level againInfologger.info ("this is Infologger's record"); }}Output result:Iv. Handler class of LoggerThe Handler object obtains the log information from the Logger and exports the Information. For example, It can write this information to a console or file, or it can send it to a blog service or forward it to the operating system log.You can disable Handler by executing setLevel (level.off) and re-enable it by performing
determine whether to write to the queue or write directly to a media.Diagram:Part of the interface functions as follows:Logmanager: Log manager, when a user instantiates a logmanager, it only needs to call write to write the log.Ilogproviderbulid: The log provider constructor that constructs the specified Ilogprovider program through a configuration fileIqueueproviderbulid: Queue provider Constructor, coinage configuration file constructs the specifi
input stream in 4 K chunks// And save to output streamConst int bufferlen = 4096;Byte [] buffer = new byte [bufferlen];Int COUNT = 0;While (COUNT = sourcestream. Read (buffer, 0, bufferlen)> 0){FS. Write (buffer, 0, count );}FS. Close ();Sourcestream. Close ();}}Catch (exception ex){Logmanager. getinstance (). writeerrorlog (string. Format ("Upload model file fail! Message: {0} ", Ex. Message ));Throw ex;}}
Finally, you can use the client class of W
the data format in which the client interacts with the server.
Therefore, I not only need to upload the logentry instance to the server from the client, but also use parameters in the action on the server to directly obtain the Log Type instance, of course, the definition of log and logentry is a policy, or there is an agreement between them. If there is no agreement, neither of them can be converted. I like the Convention more than the configuration.
Atomservicehelper. getdatafromentry (co
specify the prefix of the log file.
Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/--> Public Class Logmanager{ Private Static String Logpath = String . Empty; /// /// Folder for saving logs /// Public Static String Logpath{ Get { If (Logpath = String . Empty){ If (System. Web. httpcontext. Current = Null ) // Windows Forms applications Logp
It is configured in programming mode. This is in my project and I don't know why programming is used. Is the direct configuration not very good? It is estimated that he has not studied. The preceding steps and Code are as follows:
Create a loggingconfiguration object to save configuration information
Create at least one output target object
Set the attributes of the output target object
Set the loggingrule object and add it to the loggingrules set of the loggingconfiguration object
Enable
: weaveaction {public static void onactionbefore (methodbase mbbase) {// all information about the mbbase method to be injected var T = mbbase. getparameters (); logmanager. record ();}}
2: Mark the method to be injected
[Log]public static string GetUserName(int userId){ return "Vidar";}
3: il injection (Key Point), using mono. Cecil
Private Static void weave (ienumerable
3: After compilation is successful. The following code is displayed
log entries. For example, we add an ordered number to each log entry, for example: 16:22:50. 4218 | error |
1 | Failed logon for user John
16:22:50. 4218 | error |
2 | Failed logon for user Li Si
16:22:50. 4218 | error |
3 | Failed logon for user Wang Wu
In fact, this is not safe, because Michael can easily know that the following number is 2. In order to make Michael unable to guess the following number, we use pseudo-random numbers to make an ordered sequence. For example, use the same Ran
Public class refreshserve: system. web. UI. page {Private Static ilog log = logmanager. getlogger (typeof (refreshserve); Private readonly string refresh_ticket_name = "_ refreshticketarray"; private readonly string hidden_field_name = "_ refreshhiddenfield "; private readonly string hidden_page_guid = "_ refreshpageguid"; //
When you need to refresh the judgment function, the new page only needs to inherit this class. It can be identified by referen
,[Thread] [varchar] (255) not null,[Level] [varchar] (50) not null,[Logger] [varchar] (255) not null,[Message] [varchar] (4000) not null,[Exception] [varchar] (2000) null)How to obtain publickeytoken:Use Sn-T c: \ windows \ Microsoft. NET \ framework \ v2.0.50727 \ System. Data. dll in the vs2005 Console6. The selected appender is specified for the root node. In this example, the adonetappender is selected.7. You have configured log4net at the current location. It can be directly used in our app
Define a log class in the underlying Class Library Project
Public class LogHelper{Private static log4net. ILog log = log4net. LogManager. GetLogger ("MyLogger ");Public static void Debug (string content){Log. Debug (content );
}Public static void Info (string content){Log. Info (content );
}}
Reference log4net. dll in this class library, and
Add in assemblyInfo. cs
[Assembly: log4net. Config. DOMConfigurator (ConfigFile = "log4net. config", Watch = tr
Use log4net-1.2.0-beta8
1> set it in the assemblyinfo. CS file of the project... If you forget this step, you will not be able to monitor the log file.
[Assembly: log4net. config. domconfiguratorattribute (watch = true)]Or[Assembly: log4net. config. xmlconfigurator (watch = true)]
2> Add and edit the project configuration file (App. config by default). The content is as follows:
Content 1:
Or content 2 :]
(Content 2 can be directly copied for later use)
Use the f
You don't need to reference log4net. dll first.
The configuration and usage are as follows:
Configure in Web. config
The next step is to use
Private Static ilog log = logmanager. getlogger (typeof (mylog ));
Mylog is the current class name.
Then, you can log. Error (MSG), log. debug (MSG), and log. Warn (MSG) as needed.
Log4net is a framework component developed for recording system logs under. net. It is powerful and easy to use.
Usage:
1. Add a reference to log4net. dll in your project.
2. Set the configuration file app. config (you can also set a separate configuration file for log4net. Refer to carhui's log recording using log4net in. Net Program (example ))
Example:
When you repeatedly set the same appender in the root and logger fields, you will find that the same log information wi
The official download contains detailed instructions.
Http://logging.apache.org/log4net/download_log4net.cgi
You need to be prompted how to call in your own web or winform project to save your time. In fact, it is very simple, as long as the following code is inserted in: assemblyinfo. CS, you can successfully call
// Log4net. config is the name of the configuration file, which can be set by yourself// Watch indicates whether to monitor changes to the configuration file during the program runnin
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.