C#中的log4net目录 [英] Directory of log4net in C#
本文介绍了C#中的log4net目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
您好,
我想获取所有存在日志文件的文件。
我在下面的代码中使用但它显示了日志文件路径。我想获取日志文件的目录路径。
Hi there,
I want to get all files where log file exist.
I used below code but it shows log file path. I want to get directory path of log file.
var rootAppender = ((Hierarchy)LogManager.GetRepository())
.Root.Appenders.OfType<FileAppender>()
.FirstOrDefault();
string filename = rootAppender != null ? rootAppender.File : string.Empty;
我是什么尝试过:
我也在下面试过:
What I have tried:
I also tried below:
string curdir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);
string[] files = Directory.GetFiles(curdir);
foreach (string names in files)
{
checkedListBox1.Items.Add(names);
}
推荐答案
我不确定你想要实现的目标,但要获得一份清单您可以在当前目录中执行此文件名。
I'm not sure what you are trying to achieve, but to get a list of file names in the current directory you can do this.
var currentDirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
FileInfo[] fileInfos= currentDirectoryInfo.GetFiles();
foreach (FileInfo fileInfo in fileInfos)
{
checkedListBox1.Items.Add(fileInfo.Name);
}
听起来像是在寻找 Path.GetDirectoryName方法 [ ^ ]:
Sounds like you're looking for the Path.GetDirectoryName method[^]:
var rootAppender = ((Hierarchy)LogManager.GetRepository())
.Root.Appenders.OfType<FileAppender>()
.FirstOrDefault();
string directoryName = rootAppender != null
? Path.GetDirectoryName(rootAppender.File)
: string.Empty;
这篇关于C#中的log4net目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文