@@ -95,8 +95,7 @@ private IConfiguration TryGetConfigurationRoot()
95
95
{
96
96
if ( DefaultConfiguration != null )
97
97
{
98
- var simpleLayout = FileName as SimpleLayout ;
99
- if ( simpleLayout == null || string . IsNullOrEmpty ( simpleLayout . Text ) || ReferenceEquals ( simpleLayout . Text , DefaultFileName ) )
98
+ if ( IsDefaultConfiguration ( FileName , DefaultFileName ) )
100
99
{
101
100
if ( _configurationRoot != null )
102
101
_configurationRoot = null ;
@@ -133,26 +132,38 @@ private IConfigurationRoot LoadFileConfiguration(string fileNames)
133
132
}
134
133
}
135
134
135
+ private static bool IsDefaultConfiguration ( Layout fileName , string defaultFileName )
136
+ {
137
+ var layoutFileName = ( fileName as SimpleLayout ) ? . Text ;
138
+ return string . IsNullOrEmpty ( layoutFileName ) || ReferenceEquals ( layoutFileName , defaultFileName ) ;
139
+ }
140
+
136
141
private static IConfigurationRoot BuildConfigurationRoot ( string fileNames )
137
142
{
138
143
var configBuilder = new ConfigurationBuilder ( ) ;
144
+
139
145
string baseDir = null ;
140
146
foreach ( var fileName in fileNames . Split ( new [ ] { '|' } , StringSplitOptions . RemoveEmptyEntries ) )
141
147
{
142
- var fullPath = fileName ;
143
- if ( ! System . IO . Path . IsPathRooted ( fullPath ) )
148
+ if ( ! System . IO . Path . IsPathRooted ( fileName ) && baseDir == null )
144
149
{
145
- if ( baseDir == null )
146
- baseDir = new BaseDirLayoutRenderer ( ) . Render ( LogEventInfo . CreateNullEvent ( ) ) ?? string . Empty ;
147
- fullPath = System . IO . Path . Combine ( baseDir , fileName ) ;
150
+ baseDir = AddConfigurationBasePath ( configBuilder ) ;
148
151
}
149
152
150
- AddFileConfiguration ( configBuilder , fullPath ) ;
153
+ AddFileConfiguration ( configBuilder , fileName ) ;
151
154
}
152
155
153
156
return configBuilder . Build ( ) ;
154
157
}
155
158
159
+ private static string AddConfigurationBasePath ( ConfigurationBuilder configBuilder )
160
+ {
161
+ string baseDir = new BaseDirLayoutRenderer ( ) . Render ( LogEventInfo . CreateNullEvent ( ) ) ?? string . Empty ;
162
+ if ( ! string . IsNullOrEmpty ( baseDir ) )
163
+ configBuilder . SetBasePath ( baseDir ) ;
164
+ return baseDir ;
165
+ }
166
+
156
167
private static void AddFileConfiguration ( ConfigurationBuilder configBuilder , string fullPath )
157
168
{
158
169
if ( System . IO . File . Exists ( fullPath ) )
0 commit comments