File tree Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Expand file tree Collapse file tree 1 file changed +12
-4
lines changed Original file line number Diff line number Diff line change @@ -113,6 +113,7 @@ static int VerifyArgumentsAndRun()
113
113
return 0 ;
114
114
}
115
115
116
+
116
117
static void ConfigureLogging ( Arguments arguments )
117
118
{
118
119
var writeActions = new List < Action < string > >
@@ -129,17 +130,24 @@ static void ConfigureLogging(Arguments arguments)
129
130
{
130
131
try
131
132
{
132
- Directory . CreateDirectory ( Path . GetDirectoryName ( arguments . LogFilePath ) ) ;
133
- if ( File . Exists ( arguments . LogFilePath ) )
133
+ var logFileFullPath = Path . GetFullPath ( arguments . LogFilePath ) ;
134
+ var logFile = new FileInfo ( logFileFullPath ) ;
135
+
136
+ // NOTE: logFile.Directory will be null if the path is i.e. C:\logfile.log. @asbjornu
137
+ if ( logFile . Directory != null )
138
+ {
139
+ logFile . Directory . Create ( ) ;
140
+ }
141
+
142
+ using ( logFile . CreateText ( ) )
134
143
{
135
- using ( File . CreateText ( arguments . LogFilePath ) ) { }
136
144
}
137
145
138
146
writeActions . Add ( x => WriteLogEntry ( arguments , x ) ) ;
139
147
}
140
148
catch ( Exception ex )
141
149
{
142
- Console . WriteLine ( "Failed to configure logging: " + ex . Message ) ;
150
+ Logger . WriteError ( String . Format ( "Failed to configure logging for '{0}': {1}" , arguments . LogFilePath , ex . Message ) ) ;
143
151
}
144
152
}
145
153
You can’t perform that action at this time.
0 commit comments