NLog llog to custom directory

Hello,

I have started using NLog logging library.(currently logging to txt file)
<target> has a config like:
fileName="${basedir}/logs/logfile.txt"  

I want to log to, say D:\logfile.txt  

How can i do that ?
This seems simple but  i have failed to do it.
Thanks.
parabellumAsked:
Who is Participating?
 
mkobrinConnect With a Mentor Commented:
string path = "";
DriveInfo[] drives = DriveInfo.GetDrives();
            foreach (DriveInfo driveInfo in drives)
            {
                if (driveInfo.DriveType == DriveType.Fixed)
                {
                    if (driveInfo.Name.ToUpper() == "D")
                        path = "D:\\YourDirectoryName";
                    break;
                }
            }
            if (!Directory.Exists(path ))
            {
                Directory.CreateDirectory(path );
            }
filename = path + "\\yourFilename";
0
 
parabellumAuthor Commented:
Well there is a misunderstanding.
I want to do it in the NLog config file.
0
 
parabellumAuthor Commented:
Nevermind i have solved it.  There was one extra '$' char  that caused problems.
0
 
parabellumAuthor Commented:
Not quite the solution i wanted. But thanks for your time.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.