@@ -23,6 +23,7 @@ namespace Rubberduck
23
23
{
24
24
public sealed class App : IDisposable
25
25
{
26
+ private const string FILE_TARGET_NAME = "file" ;
26
27
private readonly VBE _vbe ;
27
28
private readonly IMessageBox _messageBox ;
28
29
private readonly IRubberduckParser _parser ;
@@ -41,7 +42,7 @@ public sealed class App : IDisposable
41
42
private readonly IConnectionPoint _projectsEventsConnectionPoint ;
42
43
private readonly int _projectsEventsCookie ;
43
44
44
- private readonly IDictionary < string , Tuple < IConnectionPoint , int > > _componentsEventsConnectionPoints =
45
+ private readonly IDictionary < string , Tuple < IConnectionPoint , int > > _componentsEventsConnectionPoints =
45
46
new Dictionary < string , Tuple < IConnectionPoint , int > > ( ) ;
46
47
private readonly IDictionary < string , Tuple < IConnectionPoint , int > > _referencesEventsConnectionPoints =
47
48
new Dictionary < string , Tuple < IConnectionPoint , int > > ( ) ;
@@ -74,7 +75,7 @@ public App(VBE vbe, IMessageBox messageBox,
74
75
75
76
_sink = new VBProjectsEventsSink ( ) ;
76
77
var connectionPointContainer = ( IConnectionPointContainer ) _vbe . VBProjects ;
77
- var interfaceId = typeof ( _dispVBProjectsEvents ) . GUID ;
78
+ var interfaceId = typeof ( _dispVBProjectsEvents ) . GUID ;
78
79
connectionPointContainer . FindConnectionPoint ( ref interfaceId , out _projectsEventsConnectionPoint ) ;
79
80
80
81
_sink . ProjectAdded += sink_ProjectAdded ;
@@ -130,9 +131,32 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
130
131
131
132
private void _configService_SettingsChanged ( object sender , EventArgs e )
132
133
{
134
+ _config = _configService . LoadConfiguration ( ) ;
133
135
// also updates the ShortcutKey text
134
136
_appMenus . Localize ( ) ;
135
137
_hooks . HookHotkeys ( ) ;
138
+ UpdateLoggingLevel ( ) ;
139
+ }
140
+
141
+ private void UpdateLoggingLevel ( )
142
+ {
143
+ var fileRule = LogManager . Configuration . LoggingRules . Where ( rule => rule . Targets . Any ( t => t . Name == FILE_TARGET_NAME ) ) . FirstOrDefault ( ) ;
144
+ if ( fileRule == null )
145
+ {
146
+ return ;
147
+ }
148
+ if ( _config . UserSettings . GeneralSettings . DetailedLoggingEnabled )
149
+ {
150
+ // "Enable" should have been called "Add" perhaps?
151
+ fileRule . EnableLoggingForLevel ( LogLevel . Trace ) ;
152
+ fileRule . EnableLoggingForLevel ( LogLevel . Debug ) ;
153
+ }
154
+ else
155
+ {
156
+ fileRule . DisableLoggingForLevel ( LogLevel . Trace ) ;
157
+ fileRule . DisableLoggingForLevel ( LogLevel . Debug ) ;
158
+ }
159
+ LogManager . ReconfigExistingLoggers ( ) ;
136
160
}
137
161
138
162
public void Startup ( )
@@ -142,6 +166,7 @@ public void Startup()
142
166
_appMenus . Localize ( ) ;
143
167
Task . Delay ( 1000 ) . ContinueWith ( t => UiDispatcher . Invoke ( ( ) => _parser . State . OnParseRequested ( this ) ) ) . ConfigureAwait ( false ) ;
144
168
_hooks . HookHotkeys ( ) ;
169
+ UpdateLoggingLevel ( ) ;
145
170
}
146
171
147
172
public void Shutdown ( )
@@ -161,7 +186,7 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
161
186
{
162
187
if ( e . Item . Protection == vbext_ProjectProtection . vbext_pp_locked )
163
188
{
164
- Debug . WriteLine ( string . Format ( "Locked project '{0}' was removed." , e . Item . Name ) ) ;
189
+ _logger . Debug ( "Locked project '{0}' was removed." , e . Item . Name ) ;
165
190
return ;
166
191
}
167
192
@@ -170,7 +195,7 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
170
195
_referencesEventsSinks . Remove ( projectId ) ;
171
196
_parser . State . RemoveProject ( e . Item ) ;
172
197
173
- Debug . WriteLine ( string . Format ( "Project '{0}' was removed." , e . Item . Name ) ) ;
198
+ _logger . Debug ( "Project '{0}' was removed." , e . Item . Name ) ;
174
199
Tuple < IConnectionPoint , int > componentsTuple ;
175
200
if ( _componentsEventsConnectionPoints . TryGetValue ( projectId , out componentsTuple ) )
176
201
{
@@ -186,18 +211,18 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
186
211
}
187
212
}
188
213
189
- private readonly IDictionary < string , VBComponentsEventsSink > _componentsEventsSinks =
190
- new Dictionary < string , VBComponentsEventsSink > ( ) ;
214
+ private readonly IDictionary < string , VBComponentsEventsSink > _componentsEventsSinks =
215
+ new Dictionary < string , VBComponentsEventsSink > ( ) ;
191
216
192
- private readonly IDictionary < string , ReferencesEventsSink > _referencesEventsSinks =
217
+ private readonly IDictionary < string , ReferencesEventsSink > _referencesEventsSinks =
193
218
new Dictionary < string , ReferencesEventsSink > ( ) ;
194
219
195
220
async void sink_ProjectAdded ( object sender , DispatcherEventArgs < VBProject > e )
196
221
{
197
- Debug . WriteLine ( string . Format ( "Project '{0}' was added." , e . Item . Name ) ) ;
222
+ _logger . Debug ( "Project '{0}' was added." , e . Item . Name ) ;
198
223
if ( e . Item . Protection == vbext_ProjectProtection . vbext_pp_locked )
199
224
{
200
- Debug . WriteLine ( "Project is protected and will not be added to parser state." ) ;
225
+ _logger . Debug ( "Project is protected and will not be added to parser state." ) ;
201
226
return ;
202
227
}
203
228
@@ -221,12 +246,12 @@ private void RegisterComponentsEventSink(VBComponents components, string project
221
246
if ( _componentsEventsSinks . ContainsKey ( projectId ) )
222
247
{
223
248
// already registered - this is caused by the initial load+rename of a project in the VBE
224
- Debug . WriteLine ( "Components sink already registered." ) ;
249
+ _logger . Debug ( "Components sink already registered." ) ;
225
250
return ;
226
251
}
227
252
228
253
var connectionPointContainer = ( IConnectionPointContainer ) components ;
229
- var interfaceId = typeof ( _dispVBComponentsEvents ) . GUID ;
254
+ var interfaceId = typeof ( _dispVBComponentsEvents ) . GUID ;
230
255
231
256
IConnectionPoint connectionPoint ;
232
257
connectionPointContainer . FindConnectionPoint ( ref interfaceId , out connectionPoint ) ;
@@ -244,7 +269,7 @@ private void RegisterComponentsEventSink(VBComponents components, string project
244
269
connectionPoint . Advise ( componentsSink , out cookie ) ;
245
270
246
271
_componentsEventsConnectionPoints . Add ( projectId , Tuple . Create ( connectionPoint , cookie ) ) ;
247
- Debug . WriteLine ( "Components sink registered and advising." ) ;
272
+ _logger . Debug ( "Components sink registered and advising." ) ;
248
273
}
249
274
250
275
async void sink_ComponentSelected ( object sender , DispatcherEventArgs < VBComponent > e )
@@ -254,7 +279,7 @@ async void sink_ComponentSelected(object sender, DispatcherEventArgs<VBComponent
254
279
return ;
255
280
}
256
281
257
- Debug . WriteLine ( string . Format ( "Component '{0}' was selected." , e . Item . Name ) ) ;
282
+ _logger . Debug ( "Component '{0}' was selected." , e . Item . Name ) ;
258
283
// do something?
259
284
}
260
285
@@ -265,7 +290,7 @@ async void sink_ComponentRenamed(object sender, DispatcherRenamedEventArgs<VBCom
265
290
return ;
266
291
}
267
292
268
- Debug . WriteLine ( "Component '{0}' was renamed to '{1}'." , e . OldName , e . Item . Name ) ;
293
+ _logger . Debug ( "Component '{0}' was renamed to '{1}'." , e . OldName , e . Item . Name ) ;
269
294
270
295
_parser . State . RemoveRenamedComponent ( e . Item , e . OldName ) ;
271
296
}
@@ -277,7 +302,7 @@ async void sink_ComponentRemoved(object sender, DispatcherEventArgs<VBComponent>
277
302
return ;
278
303
}
279
304
280
- Debug . WriteLine ( string . Format ( "Component '{0}' was removed." , e . Item . Name ) ) ;
305
+ _logger . Debug ( "Component '{0}' was removed." , e . Item . Name ) ;
281
306
_parser . State . ClearStateCache ( e . Item , true ) ;
282
307
}
283
308
@@ -288,7 +313,7 @@ async void sink_ComponentReloaded(object sender, DispatcherEventArgs<VBComponent
288
313
return ;
289
314
}
290
315
291
- Debug . WriteLine ( string . Format ( "Component '{0}' was reloaded." , e . Item . Name ) ) ;
316
+ _logger . Debug ( "Component '{0}' was reloaded." , e . Item . Name ) ;
292
317
_parser . State . OnParseRequested ( sender , e . Item ) ;
293
318
}
294
319
@@ -299,7 +324,7 @@ async void sink_ComponentAdded(object sender, DispatcherEventArgs<VBComponent> e
299
324
return ;
300
325
}
301
326
302
- Debug . WriteLine ( string . Format ( "Component '{0}' was added." , e . Item . Name ) ) ;
327
+ _logger . Debug ( "Component '{0}' was added." , e . Item . Name ) ;
303
328
_parser . State . OnParseRequested ( sender , e . Item ) ;
304
329
}
305
330
@@ -310,7 +335,7 @@ async void sink_ComponentActivated(object sender, DispatcherEventArgs<VBComponen
310
335
return ;
311
336
}
312
337
313
- Debug . WriteLine ( string . Format ( "Component '{0}' was activated." , e . Item . Name ) ) ;
338
+ _logger . Debug ( "Component '{0}' was activated." , e . Item . Name ) ;
314
339
// do something?
315
340
}
316
341
@@ -321,7 +346,7 @@ async void sink_ProjectRenamed(object sender, DispatcherRenamedEventArgs<VBProje
321
346
return ;
322
347
}
323
348
324
- Debug . WriteLine ( "Project '{0}' (ID {1}) was renamed to '{2}'." , e . OldName , e . Item . HelpFile , e . Item . Name ) ;
349
+ _logger . Debug ( "Project '{0}' (ID {1}) was renamed to '{2}'." , e . OldName , e . Item . HelpFile , e . Item . Name ) ;
325
350
_parser . State . RemoveProject ( e . Item . HelpFile ) ;
326
351
_parser . State . OnParseRequested ( sender ) ;
327
352
}
@@ -333,7 +358,7 @@ async void sink_ProjectActivated(object sender, DispatcherEventArgs<VBProject> e
333
358
return ;
334
359
}
335
360
336
- Debug . WriteLine ( string . Format ( "Project '{0}' was activated." , e . Item . Name ) ) ;
361
+ _logger . Debug ( "Project '{0}' was activated." , e . Item . Name ) ;
337
362
// do something?
338
363
}
339
364
#endregion
@@ -346,7 +371,7 @@ private void _stateBar_Refresh(object sender, EventArgs e)
346
371
347
372
private void Parser_StateChanged ( object sender , EventArgs e )
348
373
{
349
- Debug . WriteLine ( "App handles StateChanged ({0}), evaluating menu states..." , _parser . State . Status ) ;
374
+ _logger . Debug ( "App handles StateChanged ({0}), evaluating menu states..." , _parser . State . Status ) ;
350
375
_appMenus . EvaluateCanExecute ( _parser . State ) ;
351
376
}
352
377
@@ -436,7 +461,7 @@ public void Dispose()
436
461
}
437
462
438
463
if ( _autoSave != null )
439
- {
464
+ {
440
465
_autoSave . Dispose ( ) ;
441
466
_autoSave = null ;
442
467
}
0 commit comments