Skip to content

Commit 8d082a6

Browse files
committed
Add further logging configuration samples
1 parent e09b635 commit 8d082a6

File tree

3 files changed

+99
-20
lines changed

3 files changed

+99
-20
lines changed

Diff for: Logging/Logging-AddIn.dna

+2-17
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,5 @@
11
<DnaLibrary Name="Logging Add-In" RuntimeVersion="v4.0">
22
<ExternalLibrary Path="Logging.dll" LoadFromBytes="true" Pack="true" />
3-
4-
<!--
5-
The RuntimeVersion attribute above allows two settings:
6-
* RuntimeVersion="v2.0" - for .NET 2.0, 3.0 and 3.5
7-
* RuntimeVersion="v4.0" - for .NET 4 and 4.5
8-
9-
Additional referenced assemblies can be specified by adding 'Reference' tags.
10-
These libraries will not be examined and registered with Excel as add-in libraries,
11-
but will be packed into the -packed.xll file and loaded at runtime as needed.
12-
For example:
13-
14-
<Reference Path="Another.Library.dll" Pack="true" />
15-
16-
Excel-DNA also allows the xml for ribbon UI extensions to be specified in the .dna file.
17-
See the main Excel-DNA site at http://excel-dna.net for downloads of the full distribution.
18-
-->
19-
3+
<Reference Path="NLog.dll" Pack="true" />
4+
<Reference Path="log4net.dll" Pack="true" />
205
</DnaLibrary>

Diff for: Logging/Logging-AddIn.xll.config

+92-3
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,15 @@
11
<?xml version="1.0" encoding="utf-8" ?>
22
<configuration>
33

4-
<!-- This .config file contains the various configuration examples.
4+
<!--
5+
This .config file contains the various configuration examples.
56
6-
log4net
7-
NLog
7+
* log4net
8+
* NLog
9+
* ExplicitDefaults
10+
* DisableLogging
11+
* VerboseLogging
12+
* FileLogging
813
914
-->
1015

@@ -46,6 +51,7 @@
4651

4752
<!-- ============= Begin NLog ================ -->
4853

54+
<!--
4955
<configSections>
5056
<section name="nlog" type="NLog.Config.ConfigSectionHandler, NLog"/>
5157
</configSections>
@@ -72,6 +78,89 @@
7278
<logger name="*" minlevel="Warn" writeTo="debugger" />
7379
</rules>
7480
</nlog>
81+
-->
7582

7683
<!-- ============= End NLog ================ -->
84+
85+
<!-- ============= Start ExplicitDefaults ============ -->
86+
<!--
87+
This part of the sample has a configuration that is equivalent to the default configuration (when there are no entries in the .config file.
88+
This is a good start for customization of the levels or adding trace listeners.
89+
90+
By default the TraceSource is configured to source only Warning, Error and Fatal.
91+
the configuration can override this by setting switchValue attribute of the source tag (or create an explicit SourceSwitch).
92+
switchValue is a SourceLevel: Off, Critical, Error, Warning (default), Information, Verbose, All
93+
The DefaultTraceListener is automatically added to all TraceSources. It will write messages to the Debug output (if a debugger is attached to Excel).
94+
The DefaultTraceListener can be removed with a <remove name="Default"> tag in the <listeners> subtree.
95+
Excel-DNA adds the LogDisplayTraceListener to the TraceSource. By default, only Warning and Error messages are written to the LogDisplay,
96+
and the LogDisplay window is only shown if at least one Error message is written.
97+
The level of messages written to the LogDisplay can be adjusted by explicitly adding a "LogDisplay" listener of the relevant type,
98+
and setting the listener's filter to an EventTypeFilter with the correct setting.
99+
The EventTypeFiler's initializeData attribute is again a SourceLevel, i.e. one of: Off, Critical, Error, Warning (default), Information, Verbose, All.
100+
We use this filter to disable the LogDisplay completely - just set the filter to initializeData="Off".
101+
-->
102+
103+
<!--
104+
<system.diagnostics>
105+
<sources>
106+
<source name="ExcelDna.Integration" switchValue="Warning">
107+
<listeners>
108+
<add name="LogDisplay" type="ExcelDna.Logging.LogDisplayTraceListener,ExcelDna.Integration">
109+
<filter type="System.Diagnostics.EventTypeFilter" initializeData="All"/>
110+
</add>
111+
</listeners>
112+
</source>
113+
</sources>
114+
</system.diagnostics>
115+
-->
116+
117+
<!-- ============= End ExplicitDefaults ============ -->
118+
119+
<!-- ============== Start DisableLogging ============= -->
120+
<!-- This sample configuration disables all logging -->
121+
122+
<!--
123+
<system.diagnostics>
124+
<sources>
125+
<source name="ExcelDna.Integration" switchValue="Off">
126+
</source>
127+
</sources>
128+
</system.diagnostics>
129+
-->
130+
131+
<!-- ============== End DisableLogging ============= -->
132+
133+
<!-- ============== Start VerboseLogging ============= -->
134+
<!-- This sample configuration disables all logging -->
135+
136+
<!--
137+
<system.diagnostics>
138+
<sources>
139+
<source name="ExcelDna.Integration" switchValue="All">
140+
</source>
141+
</sources>
142+
</system.diagnostics>
143+
-->
144+
<!-- ============== End VerboseLogging ============= -->
145+
146+
<!-- =============== Start FileLogging ============== -->
147+
<!-- The initializeData attribute of the TextWriterTraceListener indicates the file path, either absolute or relative to the .xll.config file directory -->
148+
149+
<system.diagnostics>
150+
<trace autoflush="false" indentsize="4"/>
151+
<sources>
152+
<source name="ExcelDna.Integration" switchValue="All">
153+
<listeners>
154+
<remove name="Default"/>
155+
<add name="LogDisplay" type="ExcelDna.Logging.LogDisplayTraceListener,ExcelDna.Integration">
156+
<filter type="System.Diagnostics.EventTypeFilter" initializeData="Off"/>
157+
</add>
158+
<add name="File" type="System.Diagnostics.TextWriterTraceListener" initializeData="TextWriterOutput.log" />
159+
</listeners>
160+
</source>
161+
</sources>
162+
</system.diagnostics>
163+
164+
<!-- =============== End FileLogging ============== -->
165+
77166
</configuration>

Diff for: Logging/TestLoggers.cs

+5
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,10 @@ public void AutoOpen()
3333
}
3434

3535
public void AutoClose() { }
36+
37+
public static string GetFullPath(string fileName)
38+
{
39+
return System.IO.Path.GetFullPath(fileName);
40+
}
3641
}
3742
}

0 commit comments

Comments
 (0)