@@ -24,7 +24,6 @@ public class ScriptHost : JobHost
24
24
private const string HostAssemblyName = "ScriptHost" ;
25
25
private const string HostConfigFileName = "host.json" ;
26
26
internal const string FunctionConfigFileName = "function.json" ;
27
- private readonly TraceWriter _traceWriter ;
28
27
private readonly AutoResetEvent _restartEvent = new AutoResetEvent ( false ) ;
29
28
private Action < FileSystemEventArgs > _restart ;
30
29
private FileSystemWatcher _fileWatcher ;
@@ -38,12 +37,12 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
38
37
if ( scriptConfig . FileLoggingEnabled )
39
38
{
40
39
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 ) ;
43
42
}
44
43
else
45
44
{
46
- _traceWriter = NullTraceWriter . Instance ;
45
+ TraceWriter = NullTraceWriter . Instance ;
47
46
}
48
47
49
48
if ( scriptConfig . TraceWriter != null )
@@ -75,8 +74,8 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
75
74
// restart after ALL the operations are complete and there is a quiet period.
76
75
_restart = ( e ) =>
77
76
{
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." ) ;
80
79
81
80
// signal host restart
82
81
_restartEvent . Set ( ) ;
@@ -87,6 +86,8 @@ protected ScriptHost(ScriptHostConfiguration scriptConfig)
87
86
_directoryCountSnapshot = Directory . EnumerateDirectories ( ScriptConfig . RootScriptPath ) . Count ( ) ;
88
87
}
89
88
89
+ public TraceWriter TraceWriter { get ; private set ; }
90
+
90
91
public ScriptHostConfiguration ScriptConfig { get ; private set ; }
91
92
92
93
public Collection < FunctionDescriptor > Functions { get ; private set ; }
@@ -134,7 +135,7 @@ protected virtual void Initialize()
134
135
File . WriteAllText ( hostConfigFilePath , "{}" ) ;
135
136
}
136
137
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 ) ) ;
138
139
string json = File . ReadAllText ( hostConfigFilePath ) ;
139
140
JObject hostConfig = JObject . Parse ( json ) ;
140
141
ApplyConfiguration ( hostConfig , ScriptConfig ) ;
@@ -143,7 +144,7 @@ protected virtual void Initialize()
143
144
Collection < FunctionDescriptor > functions = ReadFunctions ( ScriptConfig , descriptionProviders ) ;
144
145
string defaultNamespace = "Host" ;
145
146
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 ) ) ;
147
148
Type type = FunctionGenerator . Generate ( HostAssemblyName , typeName , functions ) ;
148
149
List < Type > types = new List < Type > ( ) ;
149
150
types . Add ( type ) ;
@@ -168,14 +169,13 @@ public static ScriptHost Create(ScriptHostConfiguration scriptConfig = null)
168
169
}
169
170
170
171
ScriptHost scriptHost = new ScriptHost ( scriptConfig ) ;
171
-
172
172
try
173
173
{
174
174
scriptHost . Initialize ( ) ;
175
175
}
176
- catch ( Exception e )
176
+ catch ( Exception ex )
177
177
{
178
- scriptHost . _traceWriter . Error ( "Script Host initialization failed" , e ) ;
178
+ scriptHost . TraceWriter . Error ( "ScriptHost initialization failed" , ex ) ;
179
179
throw ;
180
180
}
181
181
0 commit comments