The use of log4net in WinForm

Source: Internet
Author: User

Recently in the company internship, temporarily do not have access to the Internet, home is too tired. I haven't been to update the article for a long time, but in fact, it has been the fastest progress in a few days.

Gossip does not say much, today began to consider my graduation design problem. Want to use log4net to log information. Log4net on the Internet a lot. I will not say more, I will talk about the problem solved today.

At the beginning of a separate project, using Log4net to log logs is completely fine. But later, I wanted to use it many times in the project, and I wanted to encapsulate it further, so I created a new class library project, created a new logout class, and configured it. Then on my startup Project ( Another project) called, the result is how the information can not be recorded, followed by a bit, is the monitor did not start successfully. Think for a long time reason, finally to change the path of the configuration file to absolute path, successful. But I can not later system release also use the absolute path bar, so I tried again, Copy the log4net configuration file directly to the Debug folder of the Startup project, ok!

Here are some of my code:

Encapsulated classes

Using System;
Using System.Collections.Generic;
Using System.Text;
[Assembly:log4net. Config.xmlconfigurator (configfile= "Zylog.config", Watch=true)]


Namespace Zygis. Log
{
public class LogOut
{
public static readonly log4net. ILog log = log4net. Logmanager.getlogger ("Zygis");
public static void Debug (String message)
{
if (log. isdebugenabled)
{
Log. Debug ("Debug info: \ r \ n" +message+ "\r\n\r\n");
}
}
public static void Info (String message)
{
if (log. isinfoenabled)
{
Log. info ("info: \ r \ n" + message + "\r\n\r\n");
}
}
public static void Error (String message)
{
if (log. iserrorenabled)
{
Log. Error ("wrong message: \ r \ n" + messages + "\r\n\r\n");
}
}
}
}

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.