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");
}
}
}
}