WPF uses Log4net.dll library demo (reprint plus personal point of view)

Source: Internet
Author: User
Tags log log log4net

    • Original address: http://blog.csdn.net/linraise/article/details/50547149
    • Configuration file Resolution Address: http://blog.csdn.net/pfe_nova/article/details/12225349
    • 1. Introduction of Library Log4net.dll

    • 2. Add a line in AssemblyInfo.cs: Add a line in AssemblyInfo.cs: (where log4net.config corresponds to the profile name)

[Assembly:log4net. Config.xmlconfigurator (configfile = "Log4net.config", configfileextension = "config", Watch = True)]

  

    • 3. Add the Log4net.config configuration file:
<?xml version= "1.0" encoding= "Utf-8"?><configuration> <configSections> <section name= "Log4net" Type= "System.Configuration.IgnoreSectionHandler"/> </configSections> <log4net> <appender name= " Rollinglogfileappender "Type=" log4net.      Appender.rollingfileappender "> <file value=" log\logfile.log "/> <appendtofile value=" true "/> <rollingstyle value= "Composite"/> <datepattern value= "yyyyMMdd"/> <maxsizerollbackups value= "10"/ > <maximumfilesize value= "1MB"/> <layout type= "log4net. Layout.patternlayout "> <conversionpattern value="%date [%thread]%-5level%logger [%PROPERTY{NDC}]-%message %newline "/> </layout> </appender> <root> <level value=" All "/> <appender -ref ref= "Rollinglogfileappender"/> </root> </log4net> <startup> <supportedruntime version = "v4.0" sku= ". Netframework,version=v4.5 "/> </startup></configuration> 

  

    • 4. Add a public log management class AppLog.cs
Using system;using system.collections.generic;using system.text;using log4net;using log4net. Config;using system.io;namespace log4net{///<summary>//Log Log object using the Log4net plugin///</summary> Pub        LIC Static class Applog {private static ILog log; Static Applog () {Xmlconfigurator.configureandwatch (new FileInfo (AppDomain.CurrentDomain.SetupInformatio            N.configurationfile));        Log = Logmanager.getlogger (typeof (Applog)); } public static void Debug (object message) {log.        Debug (message); public static void debugformatted (string format, params object[] args) {log.        Debugformat (format, args); } public static void Info (object message) {log.        Info (message); public static void infoformatted (string format, params object[] args) {log.        Infoformat (format, args); } public static void Warn (Object MessaGE) {log.        Warn (message); public static void Warn (Object message, Exception Exception) {log.        Warn (message, exception); public static void warnformatted (string format, params object[] args) {log.        Warnformat (format, args); } public static void Error (object message) {log.        Error (message); The public static void Error (Object message, Exception Exception) {log.        Error (message, exception); public static void errorformatted (string format, params object[] args) {log.        Errorformat (format, args); } public static void Fatal (object message) {log.        Fatal (message); public static void Fatal (Object message, Exception Exception) {log.        Fatal (message, exception);         public static void fatalformatted (string format, params object[] args) {   Log.        Fatalformat (format, args); }    }}
    • 5. Use in any place where you want to write a log, for example:
Applog.info ("Info log"); Applog.error ("Error log");

  

    • 6. Experience: Do not put the project name as log4net, or any number in the middle of the name, or the introduction of Log4net.dll will be directly error
    • 7. When the log file is not created properly or log = Logmanager.getlogger (typeof (Applog)) When the Log object has a field value of False, right-click the log4net.config Select Property --Advanced change the value copied to the project to always copy
    • This print log function does not seem to be implemented in Class 8 library projects.

WPF uses Log4net.dll library demo (reprint plus personal point of view)

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.