Skip to content

Commit 4b40f63

Browse files
committed
Merge pull request #678 from okb/feature/support-relative-logfile
Add support for relative logfile paths
2 parents 976eadc + f10b313 commit 4b40f63

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

src/GitVersionExe/Program.cs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ static int VerifyArgumentsAndRun()
113113
return 0;
114114
}
115115

116+
116117
static void ConfigureLogging(Arguments arguments)
117118
{
118119
var writeActions = new List<Action<string>>
@@ -129,17 +130,24 @@ static void ConfigureLogging(Arguments arguments)
129130
{
130131
try
131132
{
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())
134143
{
135-
using (File.CreateText(arguments.LogFilePath)) { }
136144
}
137145

138146
writeActions.Add(x => WriteLogEntry(arguments, x));
139147
}
140148
catch (Exception ex)
141149
{
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));
143151
}
144152
}
145153

0 commit comments

Comments
 (0)