如何使log4net输出到当前工作目录? [英] how do you make log4net output to current working directory?

查看:380
本文介绍了如何使log4net输出到当前工作目录?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以让log4net相对于当前工作目录而不是应用程序所在目录放置其日志文件?

Is it possible to have log4net put its log files relative to the current working directory instead of the directory where the application resides?

换句话说,如果我运行.. \ myapp.exe,我不希望.. \中的日志文件,而我希望它们在.\

In other words, if I run ..\myapp.exe, I don't want the log files in ..\ I want them in .\

推荐答案

我最终查看了log4net源,并确定可以实现自己的扩展程序,该扩展程序扩展了FileAppender并覆盖了File属性.

I ended up looking at the log4net source and determined I can implement my own appender that extends FileAppender and overrides the File property.

class CWDFileAppender : FileAppender
{
    public override string File
    {
        set
        {
            base.File = Path.Combine(Directory.GetCurrentDirectory(), value);
        }
    }
}

我只是在配置中使用CWDFileAppender.

I just use CWDFileAppender in my configuration.

这篇关于如何使log4net输出到当前工作目录?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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