使用log4net的SDK中 [英] Use log4net in SDK

查看:208
本文介绍了使用log4net的SDK中的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我提供使用C#的SDK。为了使现场调试,我想用log4net的包括记录。如何在不使用的App.config因为大会将是一个dll能配置?

I am providing an SDK using C#. To enable field debugging, I want to include logging using log4net. How to enable configuration without using App.config since the assembly will be a dll?

谢谢,

推荐答案

考虑使用XmlConfigurator来配置log4net的一个独立的配置文件的位置。您可以使用此技术,无需触摸app\web.config,也不必硬编码提供独立的基于文件的配置。例如:

Consider using XmlConfigurator to configure a standalone config file location for log4net. You can use this technique to supply independent file-based configuration without having to touch app\web.config, or having to hard-code it. Example:

http://haacked.com /archive/2005/03/07/ConfiguringLog4NetForWebApplications.aspx

更新

请尝试以下引导程序配置独立的配置文件。这将构建一个完整的路径。尝试退出的路径,如果它似乎仍然有发现它的问题。

Try the following bootstrapper to configure the standalone config file. It will construct a full path. Try logging out the path if it still appears to be having problems finding it.

public static class LogFactory
{
    public const string ConfigFileName = "log4net.config";

    public static void Configure()
    {
        Type type = typeof(LogFactory);
        FileInfo assemblyDirectory = AssemblyInfo.GetCodeBaseDirectory(type);
        string path = Path.Combine(assemblyDirectory.FullName, ConfigFileName);
        FileInfo configFile = new FileInfo(path);
        XmlConfigurator.ConfigureAndWatch(configFile);
        log4net.ILog log = LogManager.GetLogger(type);
        log.ToString();
    }
}



电话:

Call:

LogFactory.Configure();

这篇关于使用log4net的SDK中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆