, respectively defined as A.B.C and a.b, then we say A.B is the ancestor of A.B.C. Each logger inherits the ancestor's attributes.The log4net framework defines a ilog interface, and all logger classes must implement this interface. If you want to implement a custom logger, you must first implement this interface. You can refer to a few examples under the/extension directory.The Ilog interface is defined as follows: Public interface ILog { void Debug (Object message); void Info (Object message
In the following example, I will create a log that writes logs to the console and the "a. log" file.
[Csharp]Using System;Using System. Collections. Generic;Using System. Linq;Using System. Text;Using log4net;Using log4net. Appender;Using log4net. Layout;Using log4net. Repository. Hierarchy;Namespace MyLog4Net{Public class MyLog4Net{Public static ILog GetMyLog (dynamic LogName){ILog log = null;If (LogName is string){String name = (string) LogName;Log = log4net.
The common problem is not very useful. The reason is that it is too complicated. However, this item appears more and more frequently, so you have to write something for later use. This article only gives a brief description of the use of log4net. All aspects related to expansion and development are ignored.
To use log4net, you must be familiar with logger, appender, and layout. Logger is a logger. We use related methods to record logs. appender is used to set the storage mode and location of lo
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 the program directly at this level. Shouldn't it be an error! Don't be so nervous, it's actually a level of problem.
5. Log call:
Write a class at Will here, and the call is so simple. The core of
a dot-delimited hierarchy namespace to name Logger. Logger names can be arbitrary strings, but they should generally be based on the package name or class name of the component being logged, such as java.net or javax.swing. In addition, you can create an "anonymous" Logger whose name is not stored in the Logger namespace. you can obtain a Logger object by calling a GetLogger factory method. These methods either create a new Logger, or return an appro
First, create logger objectStatic Logger GetLogger (String name)Finds or creates a logger for the specified subsystem.Static Logger GetLogger (string name, String resourcebundlename)Finds or creates a logger for the specified subsystem. Note: Name is logger, and when the name is the same, only one of the logger of the same name is created.second, the level of loggerMore detailed than the log4j level, all de
file can be used to record logs in text files and SQL server databases (which of the following configuration determines when the configuration is enabled ):
Log encapsulation:
////// Log record class (recorded to the database )///Public static class LogisTracToSqlDB {private static readonly log4net. ILog m_log = LogManager. getLogger (System. reflection. methodBase. getCurrentMethod (). declaringType)
on% C (class): name of the current log object% L: the row number of the output statement% F: File Name of the output statement%-Number: indicates the minimum length of the item. If not, fill it with spaces.-->
5. Add the LogHelper. cs class to write their respective information.
Using System;Using System. Diagnostics;Using System. IO;Using System. Windows. Forms;Using log4net;[Assembly: log4net. Config. XmlConfigurator (Watch = true)]
Namespace Log4NetTest{Public class LogHelper{/// /// Log
(Exception ex) {ILog log = log4net. logManager. getLogger (this. getType (); log. error ("=================== you have caused an Error ========================" + ex. message. toString ();} return afterString ;}////// Method 2 // HashAlgorithm encryption // This encryption is a letter plus-plus character // Example: password is admin encrypted and changed to 19-A2-85-41-44-B6-3A-8F-76-17-A6-F2-25-01-9B-12
Log Management-Log4net, log-log4net
Introduction
The log4net library is implemented by the Apache log4j framework on the Micorsoft. NET platform. It is a tool that helps programmers to output log information to various targets (such as the console, files, and databases. (Baidu encyclopedia)
In actual projects, log4net is a very convenient tool for programmers to record the log information during system operation, especially for bs systems. This article briefly explains how to use it. It is the m
tag and do not need configsections.
3. Read the configuration in the application codeThis step is very simple. You can read the log4net configuration in the assemblyinfo. CS file of the application assembly.For winform applications, you can add[Assembly: log4net. config. domconfigurator ()] or[Assembly: log4net. config. xmlconfigurator ()]For webform, you can add[Assembly: log4net. config. domconfigurator (configfile = "Web. config", watch = true)]
Note: If you are using a nunit test friend, us
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 = "C :\\ testproj \ testprojlog4net.txt"/>
5. perform the following steps on the code page:
A. Add a namespac
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
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.