Add reference log4net. DLL to the project. The latest version is 1.2.10.0. Execute configure ONCE during initialization. Log4net. config. xmlconfigurator
. Configure (New fileinfo ("logconfig. xml"); declare log in the class to be used. Use typeof (Class Name) as a parameter. Private log4net. ilog log = log4net. logmanager. getlogger (typeof (someclass); Use: If (log. isdebugenabled) log. debug ("some message ");//... try {...} catch (exception ex) {l
later versions. CS files cannot be added to each class that requires log4net.Code. In this case, there are two solutions on the Internet: (1) create a class library to inherit from log4, load the configuration in the [Assembly] mode, and reference the class library in the web project; (2) dynamically load configurations in the Global File. I personally think that the methods provided by log4net are ready for use and there is no need to inherit them. We recommend using the (2) method.
2. Use o
trackbackitem, string parameters) sends byte streams according to the length of the ASCII code. When parameters contains Chinese characters, there will be errors, the solution is to convert to UTF-8 to send, below is my modifiedCode:
Private void sendping (string trackbackitem, string parameters){
Httpwebrequest request = blogrequest. createrequest (trackbackitem );Request. method = "Post ";
Request. contenttype = "application/X-WWW-form-urlencoded ";Request. keepalive = false;
Byte [] b
1. Web. config:
2. log4net_config_file.xml
3. CS:
Private Static readonly ilog logger = logmanager. getlogger ("logger_name ");//... if (logger. isdebugenabled) {logger. debug ("returned data upon request:" + some infomation );}
How do I enable log4net innteral debugging?
There are 2 different ways to enable internal debugging in log4net. These are listed below. The preferred method is to specifyLog4net. Internal. DebugOption
Over the past few days, I have been studying the socket program connected to. Net by Delphi, and finally made some progress.
Requirements:
The server intercepts the first four bytes and converts them to numbers. The second digit is the Business Code. It determines which business logic to call.
Using system; using system. collections. generic; using system. text; using system. io; using system. net. sockets; using system. threading; using pivasupdate; using log4net; using system. reflection; usi
= logmanager. getlogger ("testremote ");Remotelogger.info ("blabla ");}}
Server:
The server uses the socketserver class. This class provides the main function, which can be directly run, but pay attention to the use of parameters:
The following is an example:
Java-CP log4j-1.2.16.jar org.apache.log4j.net. socketserver 4560/data/log4j/log4jserver. properties/data/log4j/LCF/
4560 is the listening port. It seems that socketappender is also the default p
documentation. In this way, all programs compiled later will come with an XML file, which is an important file for generating help documents.
3. Add instructions in the program. The method is as follows:Namespace danganguanli. logsystem{/// /// Log-related operation set, which is implemented through log4net./// /// /// /// Public class loghelper{/// /// Create a loginfo Log Type/// Public static readonly log4net. ilog loginfo = log4net. logmanager. g
Class for resumable upload and download of Files written in C #
This example uses C # upload and Servlet for receiving.
C # resumable download of files as clients and servlets as servers
There is debugging failed, mail me: lijiangchxp@sina.com.cn
Using system;Using log4net;Using system. collections;Using system. text;Using system. IO;Using system. net;Using log4net. config;Using chxp. business;Namespace chxp. Service{Public class filelib{# Region attributesPrivate string filename = "";Public Str
). localPath );}Var log = LogManager. Default. GetLogger ("Dicom. Imaging. Codec ");Var catalog = (search = null )? New DirectoryCatalog (path): new DirectoryCatalog (path, search); var container = new CompositionContainer (catiner); foreach (var lazy in container. getExports When it is the Console, the above path is the path of the exe, so the MEF mechanism can find Dicom. Native. DLL, and then you can get the Codecs.When it is AspNet WebApi, the ab
Spring transaction configuration, spring transaction1. Declarative transaction Configuration* Configure SessionFactory* Configure the Transaction Manager* Propagation Features of transactions* The methods of those classes use transactions.
The specific configuration is as follows:
In this way, you do not need to write the code used to manage transactions in the Code:
Public void addUser (User user)Throws Exception {// This. getSession (). save (user );This. getHibernateTemplate (). save (user )
Log4net cannot output logs, and the tracing finds that IsErrorEnabled and so on are Flase.
Because this is a half-outsourcing project, the writing method is different from my previous habits, so I didn't see what went wrong.
The Code is as follows:ILog Log = LogManager. GetLogger (MethodBase. GetCurrentMethod (). DeclaringType );
Page_Load (sender, EventArgs e)
{
{
Log. Error ();
}
(Exception ex)
{
Log. Error ();
}
}
Log4net configuration is placed
C # obtain the remote image. The Authorization authentication of the Form user name and password is required.
Copy codeThe Code is as follows: using System;
Using System. Collections. Generic;
Using System. Drawing;
Using System. IO;
Using System. Linq;
Using System. Net;
Using System. Text;
Using System. Web;
Using System. Web. UI;
Using System. Web. UI. WebControls;
Namespace Web. App_Code{Public partial class GetFlexImage: System. Web. UI. Page{Public static readonly log4net. ILog log = log4
Continue to do. Net winform project, from vs2002, 2003 to 2005. Although ms vs is getting dumb, it still makes people think that many things are complicated.
For example, database operations, such as writing basic classes and methods. Of course, in 2005, the macro provided by vs is a very good tool, but according to my contacts, it is not much better than what we use. In view of the habits of thinking and coding habits. Gradually encapsulate some abstract methods and structures.
Build a set of
IbeammdaaUseCommon. LoggingAs a log output component, it is easy to use,CodeAs follows:
IlogLog =Logmanager. Getlogger (This. GetType ());
LOg. Info ("Log Information");
How to configureCommon. LoggingSee"Ibeammdaa"Application Server Configuration" section.
When using the log component, you must also pay attention to the log level. Instead of outputting all levels of logs, there are too many log data, but it is difficult to find useful inf
There is a log4net User Guide in the garden, which is detailed. We recommend that you use log4net.
If you don't want to spend too much time on research, you can do it in five minutes by following the steps below:
1. Add a reference to log4net. dll
2. modify the configuration file. Take app. config as an example. The reference content is as follows:
3. Example
Code
Using system; using log4net; namespace console_demo {class program {static void main (string [] ARGs) {log4net. config. xmlc
= "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 = lo
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.