Skip to content

Commit e6e991d

Browse files
Andrin Meierretailcoder
authored andcommitted
Configure logging (#1563)
* clean up file statements (fixes #1487) * consider members in supertypes as members of enclosing module (fixes #1489) * remove temp fix (should be fixed with #1489) * add support for Circle and Scale special forms (fixes #1498) * fix foreign names (#1521) * speed up all parsers by using the "two-stage parsing" approach * reenable "function return value not used" inspection * clean up * fix typeof expression resolver * configure logging * make rollover size 5MB
1 parent 9bd8d08 commit e6e991d

File tree

12 files changed

+639
-525
lines changed

12 files changed

+639
-525
lines changed

RetailCoder.VBE/App.cs

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ namespace Rubberduck
2323
{
2424
public sealed class App : IDisposable
2525
{
26+
private const string FILE_TARGET_NAME = "file";
2627
private readonly VBE _vbe;
2728
private readonly IMessageBox _messageBox;
2829
private readonly IRubberduckParser _parser;
@@ -41,7 +42,7 @@ public sealed class App : IDisposable
4142
private readonly IConnectionPoint _projectsEventsConnectionPoint;
4243
private readonly int _projectsEventsCookie;
4344

44-
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
45+
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _componentsEventsConnectionPoints =
4546
new Dictionary<string, Tuple<IConnectionPoint, int>>();
4647
private readonly IDictionary<string, Tuple<IConnectionPoint, int>> _referencesEventsConnectionPoints =
4748
new Dictionary<string, Tuple<IConnectionPoint, int>>();
@@ -74,7 +75,7 @@ public App(VBE vbe, IMessageBox messageBox,
7475

7576
_sink = new VBProjectsEventsSink();
7677
var connectionPointContainer = (IConnectionPointContainer)_vbe.VBProjects;
77-
var interfaceId = typeof (_dispVBProjectsEvents).GUID;
78+
var interfaceId = typeof(_dispVBProjectsEvents).GUID;
7879
connectionPointContainer.FindConnectionPoint(ref interfaceId, out _projectsEventsConnectionPoint);
7980

8081
_sink.ProjectAdded += sink_ProjectAdded;
@@ -130,9 +131,32 @@ private bool ShouldEvaluateCanExecute(Declaration selectedDeclaration, ParserSta
130131

131132
private void _configService_SettingsChanged(object sender, EventArgs e)
132133
{
134+
_config = _configService.LoadConfiguration();
133135
// also updates the ShortcutKey text
134136
_appMenus.Localize();
135137
_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();
136160
}
137161

138162
public void Startup()
@@ -142,6 +166,7 @@ public void Startup()
142166
_appMenus.Localize();
143167
Task.Delay(1000).ContinueWith(t => UiDispatcher.Invoke(() => _parser.State.OnParseRequested(this))).ConfigureAwait(false);
144168
_hooks.HookHotkeys();
169+
UpdateLoggingLevel();
145170
}
146171

147172
public void Shutdown()
@@ -186,10 +211,10 @@ async void sink_ProjectRemoved(object sender, DispatcherEventArgs<VBProject> e)
186211
}
187212
}
188213

189-
private readonly IDictionary<string,VBComponentsEventsSink> _componentsEventsSinks =
190-
new Dictionary<string,VBComponentsEventsSink>();
214+
private readonly IDictionary<string, VBComponentsEventsSink> _componentsEventsSinks =
215+
new Dictionary<string, VBComponentsEventsSink>();
191216

192-
private readonly IDictionary<string,ReferencesEventsSink> _referencesEventsSinks =
217+
private readonly IDictionary<string, ReferencesEventsSink> _referencesEventsSinks =
193218
new Dictionary<string, ReferencesEventsSink>();
194219

195220
async void sink_ProjectAdded(object sender, DispatcherEventArgs<VBProject> e)
@@ -226,7 +251,7 @@ private void RegisterComponentsEventSink(VBComponents components, string project
226251
}
227252

228253
var connectionPointContainer = (IConnectionPointContainer)components;
229-
var interfaceId = typeof (_dispVBComponentsEvents).GUID;
254+
var interfaceId = typeof(_dispVBComponentsEvents).GUID;
230255

231256
IConnectionPoint connectionPoint;
232257
connectionPointContainer.FindConnectionPoint(ref interfaceId, out connectionPoint);
@@ -436,7 +461,7 @@ public void Dispose()
436461
}
437462

438463
if (_autoSave != null)
439-
{
464+
{
440465
_autoSave.Dispose();
441466
_autoSave = null;
442467
}

RetailCoder.VBE/NLog.dll.nlog

Lines changed: 22 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,25 +2,32 @@
22
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
autoReload="true">
5-
6-
<!-- define various log targets -->
75
<targets>
8-
<!-- write logs to file -->
9-
<target xsi:type="File" name="file"
10-
fileName="${specialfolder:folder=ApplicationData}/Rubberduck/logs/${logger}.log"
11-
layout="${longdate} ${processid} ${uppercase:${level}} ${message} ${exception:format=tostring}" />
12-
13-
<!-- log message to event log -->
14-
<target xsi:type="EventLog" name="eventLog" source="RubberDuck.VBE" eventId="${event-properties:EventID}"
15-
layout="${message}${newline}Call site: ${callsite:className=true:methodName=true}${newline}Logger: ${logger}${newline}${exception:format=tostring}">
6+
<target
7+
xsi:type="File"
8+
name="file"
9+
fileName="${specialfolder:folder=ApplicationData}/Rubberduck/logs/rubberduck.log"
10+
layout="${longdate};${uppercase:${level}};${logger};${message};${exception:format=tostring}"
11+
archiveFileName="${specialfolder:folder=ApplicationData}/Rubberduck/logs/archives/log.{#####}.log"
12+
archiveAboveSize="5242880"
13+
archiveNumbering="Sequence"
14+
concurrentWrites="true"
15+
keepFileOpen="false"
16+
encoding="UTF-8"/>
17+
<target
18+
xsi:type="EventLog"
19+
name="eventlog"
20+
source="Rubberduck-VBA"
21+
layout="${message}${newline}Call site: ${callsite:className=true:methodName=true}${newline}Logger: ${logger}${newline}${exception:format=tostring}">
1622
</target>
17-
18-
<!-- increase the performance counter -->
19-
<!--target xsi:type="PerfCounter" name="pc1" categoryName="My Log" counterName="My Counter">
20-
</target-->
23+
<target
24+
xsi:type="Debugger"
25+
name="debuglog"
26+
layout="${longdate};${uppercase:${level}};${logger};${message};${exception:format=tostring}"/>
2127
</targets>
2228
<rules>
23-
<logger name="*" minlevel="Trace" writeTo="file" />
29+
<logger name="*" minlevel="Info" writeTo="file" />
2430
<logger name="*" minlevel="Error" writeTo="eventlog"/>
31+
<logger name="*" minlevel="Trace" writeTo="debuglog" />
2532
</rules>
2633
</nlog>

RetailCoder.VBE/Rubberduck.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1547,10 +1547,10 @@
15471547
</Target>
15481548
<Import Project="..\packages\Antlr4.4.3.0\build\Antlr4.targets" Condition="Exists('..\packages\Antlr4.4.3.0\build\Antlr4.targets')" />
15491549
<PropertyGroup>
1550-
<PostBuildEvent>eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO RubberDuck.VBE /D "Successfully deployed Rubberduck from Visual Studio Build"</PostBuildEvent>
1550+
<PostBuildEvent>eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO "Rubberduck-VBA" /D "Successfully deployed Rubberduck from Visual Studio Build"</PostBuildEvent>
15511551
</PropertyGroup>
15521552
<PropertyGroup>
1553-
<PreBuildEvent>eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO RubberDuck.VBE /D "Deploying Rubberduck from Visual Studio Build"</PreBuildEvent>
1553+
<PreBuildEvent>eventcreate /ID 1 /L APPLICATION /T INFORMATION /SO "Rubberduck-VBA" /D "Deploying Rubberduck from Visual Studio Build"</PreBuildEvent>
15541554
</PropertyGroup>
15551555
<Import Project="$(SolutionDir)\.nuget\NuGet.targets" Condition="Exists('$(SolutionDir)\.nuget\NuGet.targets')" />
15561556
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.

RetailCoder.VBE/Settings/GeneralSettings.cs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ public interface IGeneralSettings
88
bool AutoSaveEnabled { get; set; }
99
int AutoSavePeriod { get; set; }
1010
char Delimiter { get; set; }
11+
bool DetailedLoggingEnabled { get; set; }
1112
}
1213

1314
[XmlType(AnonymousType = true)]
@@ -17,21 +18,28 @@ public class GeneralSettings : IGeneralSettings
1718
public bool AutoSaveEnabled { get; set; }
1819
public int AutoSavePeriod { get; set; }
1920
public char Delimiter { get; set; }
21+
public bool DetailedLoggingEnabled { get; set; }
2022

2123
public GeneralSettings()
2224
{
2325
Language = new DisplayLanguageSetting("en-US");
2426
AutoSaveEnabled = false;
2527
AutoSavePeriod = 10;
2628
Delimiter = '.';
29+
DetailedLoggingEnabled = false;
2730
}
2831

29-
public GeneralSettings(DisplayLanguageSetting language, bool autoSaveEnabled, int autoSavePeriod)
32+
public GeneralSettings(
33+
DisplayLanguageSetting language,
34+
bool autoSaveEnabled,
35+
int autoSavePeriod,
36+
bool detailedLoggingEnabled)
3037
{
3138
Language = language;
3239
AutoSaveEnabled = autoSaveEnabled;
3340
AutoSavePeriod = autoSavePeriod;
3441
Delimiter = '.';
42+
DetailedLoggingEnabled = detailedLoggingEnabled;
3543
}
3644
}
3745
}

0 commit comments

Comments
 (0)