Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.

C#
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:

C#
string curdir = System.IO.Path.GetDirectoryName(Application.ExecutablePath);

string[] files = Directory.GetFiles(curdir);


foreach (string names in files)
{
     checkedListBox1.Items.Add(names);
}
Posted
Updated 6-Jun-16 9:33am
v2

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.


C#
var currentDirectoryInfo = new DirectoryInfo(Directory.GetCurrentDirectory());
           FileInfo[] fileInfos= currentDirectoryInfo.GetFiles();

            foreach (FileInfo fileInfo in fileInfos)
            {
                checkedListBox1.Items.Add(fileInfo.Name);
            }
 
Share this answer
 
Sounds like you're looking for the Path.GetDirectoryName method[^]:
C#
var rootAppender = ((Hierarchy)LogManager.GetRepository())
                                         .Root.Appenders.OfType<FileAppender>()
                                         .FirstOrDefault();

string directoryName = rootAppender != null 
    ? Path.GetDirectoryName(rootAppender.File) 
    : string.Empty;
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900