Menu

#2 Exception if LogBasePath not found

v1.0_(example)
open
Dave
None
5
2016-04-29
2016-04-29
ReS
No

Hi,

I think you forgot something. When you define a own Folder to log files and this this directory does not exist you will get an exception.
Eg. I try to use

Log.LogBasePath = @"C:\xyz\logs";

My solution to this -> I added in your SetLogPath() the following line:

if (!Directory.Exists(m_logbasepath)) {
    Directory.CreateDirectory(m_logbasepath); 
}

right here:

string sFilePath;
            if (m_logbasepath == string.Empty) {
                sFilePath = Environment.CurrentDirectory.TrimEnd('\\') + "\\" + LogName + "_" + sPeriod + m_logfiletype;
            }
            else {
                if (!Directory.Exists(m_logbasepath)) {
                    Directory.CreateDirectory(m_logbasepath); 
                    }
                sFilePath = m_logbasepath.TrimEnd('\\') + @"\" + LogName + "_" + sPeriod + m_logfiletype;
            }

maybe there's a better way to place this line - but this works fine :)

Regards
Robert

Discussion


Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.