@@ -24,7 +24,6 @@ public class ScriptHost : JobHost
2424 private const string HostAssemblyName = "ScriptHost" ;
2525 private const string HostConfigFileName = "host.json" ;
2626 internal const string FunctionConfigFileName = "function.json" ;
27- private readonly TraceWriter _traceWriter ;
2827 private readonly AutoResetEvent _restartEvent = new AutoResetEvent ( false ) ;
2928 private Action < FileSystemEventArgs > _restart ;
3029 private FileSystemWatcher _fileWatcher ;
@@ -38,12 +37,12 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
3837 if ( scriptConfig . FileLoggingEnabled )
3938 {
4039 string hostLogFilePath = Path . Combine ( scriptConfig . RootLogPath , "Host" ) ;
41- _traceWriter = new FileTraceWriter ( hostLogFilePath , TraceLevel . Verbose ) ;
42- scriptConfig . HostConfig . Tracing . Tracers . Add ( _traceWriter ) ;
40+ TraceWriter = new FileTraceWriter ( hostLogFilePath , TraceLevel . Verbose ) ;
41+ scriptConfig . HostConfig . Tracing . Tracers . Add ( TraceWriter ) ;
4342 }
4443 else
4544 {
46- _traceWriter = NullTraceWriter . Instance ;
45+ TraceWriter = NullTraceWriter . Instance ;
4746 }
4847
4948 if ( scriptConfig . TraceWriter != null )
@@ -75,8 +74,8 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
7574 // restart after ALL the operations are complete and there is a quiet period.
7675 _restart = ( e ) =>
7776 {
78- _traceWriter . Verbose ( string . Format ( CultureInfo . InvariantCulture , "File change of type '{0}' detected for '{1}'" , e . ChangeType , e . FullPath ) ) ;
79- _traceWriter . Verbose ( "Host configuration has changed. Signaling restart." ) ;
77+ TraceWriter . Verbose ( string . Format ( CultureInfo . InvariantCulture , "File change of type '{0}' detected for '{1}'" , e . ChangeType , e . FullPath ) ) ;
78+ TraceWriter . Verbose ( "Host configuration has changed. Signaling restart." ) ;
8079
8180 // signal host restart
8281 _restartEvent . Set ( ) ;
@@ -87,6 +86,8 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
8786 _directoryCountSnapshot = Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) . Count ( ) ;
8887 }
8988
89+ public TraceWriter TraceWriter { get ; private set ; }
90+
9091 public ScriptHostConfiguration ScriptConfig { get ; private set ; }
9192
9293 public Collection < FunctionDescriptor > Functions { get ; private set ; }
@@ -134,7 +135,7 @@ protected virtual void Initialize()
134135 File . WriteAllText ( hostConfigFilePath , "{}" ) ;
135136 }
136137
137- _traceWriter . Verbose ( string . Format ( CultureInfo . InvariantCulture , "Reading host configuration file '{0}'" , hostConfigFilePath ) ) ;
138+ TraceWriter . Verbose ( string . Format ( CultureInfo . InvariantCulture , "Reading host configuration file '{0}'" , hostConfigFilePath ) ) ;
138139 string json = File . ReadAllText ( hostConfigFilePath ) ;
139140 JObject hostConfig = JObject . Parse ( json ) ;
140141 ApplyConfiguration ( hostConfig , ScriptConfig ) ;
@@ -143,7 +144,7 @@ protected virtual void Initialize()
143144 Collection < FunctionDescriptor > functions = ReadFunctions ( ScriptConfig , descriptionProviders ) ;
144145 string defaultNamespace = "Host" ;
145146 string typeName = string . Format ( CultureInfo . InvariantCulture , "{0}.{1}" , defaultNamespace , "Functions" ) ;
146- _traceWriter . Verbose ( string . Format ( CultureInfo . InvariantCulture , "Generating {0} job function(s)" , functions . Count ) ) ;
147+ TraceWriter . Verbose ( string . Format ( CultureInfo . InvariantCulture , "Generating {0} job function(s)" , functions . Count ) ) ;
147148 Type type = FunctionGenerator . Generate ( HostAssemblyName , typeName , functions ) ;
148149 List < Type > types = new List < Type > ( ) ;
149150 types . Add ( type ) ;
@@ -168,14 +169,13 @@ public static ScriptHost Create(ScriptHostConfiguration scriptConfig = null)
168169 }
169170
170171 ScriptHost scriptHost = new ScriptHost ( scriptConfig ) ;
171-
172172 try
173173 {
174174 scriptHost . Initialize ( ) ;
175175 }
176- catch ( Exception e )
176+ catch ( Exception ex )
177177 {
178- scriptHost . _traceWriter . Error ( "Script Host initialization failed" , e ) ;
178+ scriptHost . TraceWriter . Error ( "ScriptHost initialization failed" , ex ) ;
179179 throw ;
180180 }
181181
0 commit comments