Solved

NLog llog to custom directory

Posted on 2011-02-17
4
655 Views
Last Modified: 2013-12-17
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.
0
Comment
Question by:parabellum
  • 3
4 Comments
 
LVL 7

Accepted Solution

by:
mkobrin earned 500 total points
ID: 34915061
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
 

Author Comment

by:parabellum
ID: 34916223
Well there is a misunderstanding.
I want to do it in the NLog config file.
0
 

Author Comment

by:parabellum
ID: 34916732
Nevermind i have solved it.  There was one extra '$' char  that caused problems.
0
 

Author Closing Comment

by:parabellum
ID: 34916742
Not quite the solution i wanted. But thanks for your time.
0

Featured Post

DevOps Toolchain Recommendations

Read this Gartner Research Note and discover how your IT organization can automate and optimize DevOps processes using a toolchain architecture.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is for Object-Oriented Programming (OOP) beginners. An Interface contains declarations of events, indexers, methods and/or properties. Any class which implements the Interface should provide the concrete implementation for each Inter…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…
A company’s greatest vulnerability is their email. CEO fraud, ransomware and spear phishing attacks are the no1 threat to a company’s security. Cybercrime is responsible for the largest loss of money to companies today with losses projected to r…

914 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now