log4net无法输出日志
答案:2 悬赏:80
解决时间 2021-02-11 16:50
- 提问者网友:冥界祭月
- 2021-02-11 10:31
log4net无法输出日志
最佳答案
- 二级知识专家网友:陪衬角色
- 2021-02-11 11:49
在命名空间前面加上
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
试试
[assembly: log4net.Config.XmlConfigurator(Watch = true)]
试试
全部回答
- 1楼网友:陪伴是最长情的告白
- 2021-02-11 13:20
建立一个dll,先写一个类,引用log4Net.dll
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
public class Logger
{
public static bool GetTracerSwitchor()
{
string configPath = Application.StartupPath + "\\eSerialPro.exe";
System.Configuration.Configuration config = System.Configuration.ConfigurationManager.OpenExeConfiguration(configPath);
bool IsTracer = Convert.ToBoolean(config.AppSettings.Settings["IsTracer"].Value);
return IsTracer;
}
///
/// 调试信息
///
///
public static void Debug(string msg)
{
bool IsTracer = GetTracerSwitchor();
if (IsTracer)
{
log4net.ILog log = log4net.LogManager.GetLogger("Test");
if (log.IsDebugEnabled)
{
log.Debug(msg);
}
log = null;
}
}
}
这样调用
再在Assembly里加入信息
[assembly: log4net.Config.XmlConfigurator(ConfigFile = "log4net.config", Watch = true)]
再在可执行程序的根目录下,写一个名为log4net.appconfig文件,内容如下
C# code?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯