Permalink
Browse files

Updates to better support Silverlight

Added support for NLog.config inside xap file for Silverlight
Enabled include file support for Silverlight (inside XAP).
Updated MessageBoxTarget to always show message box on the UI thread.
Added ${sl-appinfo} layout renderer.
  • Loading branch information...
1 parent 17e016b commit 215106a6a723961757164e9ba40d0ad7ed17a87d @jkowalski jkowalski committed Jun 23, 2010
Showing with 733 additions and 83 deletions.
  1. +2 −2 .gitignore
  2. +6 −0 src/NLog.sl4.sln
  3. +19 −1 src/NLog/Config/XmlLoggingConfiguration.cs
  4. +105 −0 src/NLog/LayoutRenderers/SilverlightApplicationInfoLayoutRenderer.cs
  5. +66 −0 src/NLog/LayoutRenderers/SilverlightApplicationInfoOption.cs
  6. +11 −3 src/NLog/LogFactory.cs
  7. +2 −0 src/NLog/NLog.doc.csproj
  8. +2 −0 src/NLog/NLog.mono2.csproj
  9. +2 −0 src/NLog/NLog.netcf20.csproj
  10. +2 −0 src/NLog/NLog.netcf35.csproj
  11. +2 −0 src/NLog/NLog.netfx20.csproj
  12. +2 −0 src/NLog/NLog.netfx35.csproj
  13. +2 −0 src/NLog/NLog.netfx40.csproj
  14. +2 −0 src/NLog/NLog.sl2.csproj
  15. +2 −0 src/NLog/NLog.sl3.csproj
  16. +2 −0 src/NLog/NLog.sl4.csproj
  17. +13 −2 src/NLog/Targets/MessageBoxTarget.cs
  18. +3 −0 tests/NLog.UnitTests/App.xaml.cs
  19. +63 −41 tests/NLog.UnitTests/Config/IncludeTests.cs
  20. +5 −0 tests/NLog.UnitTests/ConfigFiles/included.nlog
  21. +7 −0 tests/NLog.UnitTests/ConfigFiles/main.nlog
  22. +7 −0 tests/NLog.UnitTests/ConfigFiles/referencemissingfile.nlog
  23. +9 −0 tests/NLog.UnitTests/ConfigFiles/referencemissingfileignored.nlog
  24. +7 −2 tests/NLog.UnitTests/NLog.UnitTests.netcf20.csproj
  25. +7 −2 tests/NLog.UnitTests/NLog.UnitTests.netcf35.csproj
  26. +8 −4 tests/NLog.UnitTests/NLog.UnitTests.netfx20.csproj
  27. +8 −4 tests/NLog.UnitTests/NLog.UnitTests.netfx35.csproj
  28. +8 −4 tests/NLog.UnitTests/NLog.UnitTests.netfx40.csproj
  29. +10 −8 tests/NLog.UnitTests/NLog.UnitTests.sl2.csproj
  30. +8 −4 tests/NLog.UnitTests/NLog.UnitTests.sl3.csproj
  31. +10 −6 tests/NLog.UnitTests/NLog.UnitTests.sl4.csproj
  32. +28 −0 tests/NLog.UnitTests/ProjectFileInfo.xml
  33. +8 −0 tests/SilverlightApp/App.xaml
  34. +74 −0 tests/SilverlightApp/App.xaml.cs
  35. +13 −0 tests/SilverlightApp/MainPage.xaml
  36. +31 −0 tests/SilverlightApp/MainPage.xaml.cs
  37. +8 −0 tests/SilverlightApp/NLog.config
  38. +6 −0 tests/SilverlightApp/Properties/AppManifest.xml
  39. +34 −0 tests/SilverlightApp/Properties/AssemblyInfo.cs
  40. +7 −0 tests/SilverlightApp/Properties/OutOfBrowserSettings.xml
  41. +122 −0 tests/SilverlightApp/SilverlightApp.sl4.csproj
View
@@ -1,5 +1,6 @@
obj/
bin/
+Bin/
msbuild.log
LastTestRunSummary.cmd
src/Docs/Working/
@@ -15,5 +16,4 @@ StyleCop.Cache
NLogMerged.api.xml
_UpgradeReport_Files/
UpgradeLog*.XML
-
-
+*.xap
View
@@ -8,6 +8,8 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "NLog.UnitTests.sl4", "..\te
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SampleExtensions.sl4", "..\tests\SampleExtensions\SampleExtensions.sl4.csproj", "{C480452F-7E14-443D-906D-7E021AB5707A}"
EndProject
+Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SilverlightApp.sl4", "..\tests\SilverlightApp\SilverlightApp.sl4.csproj", "{6BDB11AF-E5F0-43D2-B823-371E5B79087C}"
+EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
@@ -30,6 +32,10 @@ Global
{C480452F-7E14-443D-906D-7E021AB5707A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C480452F-7E14-443D-906D-7E021AB5707A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C480452F-7E14-443D-906D-7E021AB5707A}.Release|Any CPU.Build.0 = Release|Any CPU
+ {6BDB11AF-E5F0-43D2-B823-371E5B79087C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
+ {6BDB11AF-E5F0-43D2-B823-371E5B79087C}.Debug|Any CPU.Build.0 = Debug|Any CPU
+ {6BDB11AF-E5F0-43D2-B823-371E5B79087C}.Release|Any CPU.ActiveCfg = Release|Any CPU
+ {6BDB11AF-E5F0-43D2-B823-371E5B79087C}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
@@ -141,7 +141,11 @@ public XmlLoggingConfiguration(XmlReader reader, string fileName, bool ignoreErr
if (fileName != null)
{
InternalLogger.Info("Configuring from an XML element in {0}...", fileName);
+#if SILVERLIGHT
+ string key = fileName;
+#else
string key = Path.GetFullPath(fileName);
+#endif
this.visitedFile[key] = true;
this.originalFileName = fileName;
@@ -214,7 +218,12 @@ public override LoggingConfiguration Reload()
private void ConfigureFromFile(string fileName)
{
+#if SILVERLIGHT
+ // file names are relative to XAP
+ string key = fileName;
+#else
string key = Path.GetFullPath(fileName);
+#endif
if (this.visitedFile.ContainsKey(key))
{
return;
@@ -807,9 +816,18 @@ private void ParseIncludeElement(XmlReader reader, string baseDirectory)
try
{
- newFileName = Path.Combine(baseDirectory, SimpleLayout.Evaluate(newFileName));
+ newFileName = SimpleLayout.Evaluate(newFileName);
+ if (baseDirectory != null)
+ {
+ newFileName = Path.Combine(baseDirectory, newFileName);
+ }
+#if SILVERLIGHT
+ newFileName = newFileName.Replace("\\", "/");
+ if (Application.GetResourceStream(new Uri(newFileName, UriKind.Relative)) != null)
+#else
if (File.Exists(newFileName))
+#endif
{
InternalLogger.Debug("Including file '{0}'", newFileName);
this.ConfigureFromFile(newFileName);
@@ -0,0 +1,105 @@
+//
+// Copyright (c) 2004-2010 Jaroslaw Kowalski <jaak@jkowalski.net>
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * Neither the name of Jaroslaw Kowalski nor the names of its
+// contributors may be used to endorse or promote products derived from this
+// software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+// THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+#if SILVERLIGHT || DOCUMENTATION
+
+namespace NLog.LayoutRenderers
+{
+ using System;
+ using System.ComponentModel;
+ using System.Text;
+#if !DOCUMENTATION
+ using System.Windows;
+ using System.Windows.Browser;
+ using NLog.Config;
+
+#endif
+
+ /// <summary>
+ /// Information about Silverlight application.
+ /// </summary>
+ [LayoutRenderer("sl-appinfo")]
+ public class SilverlightApplicationInfoLayoutRenderer : LayoutRenderer
+ {
+ /// <summary>
+ /// Initializes a new instance of the <see cref="SilverlightApplicationInfoLayoutRenderer"/> class.
+ /// </summary>
+ public SilverlightApplicationInfoLayoutRenderer()
+ {
+ this.Option = SilverlightApplicationInfoOption.XapUri;
+ }
+
+ /// <summary>
+ /// Gets or sets specific information to display.
+ /// </summary>
+ /// <docgen category='Rendering Options' order='10' />
+ [DefaultParameter]
+ [DefaultValue(SilverlightApplicationInfoOption.XapUri)]
+ public SilverlightApplicationInfoOption Option { get; set; }
+
+ /// <summary>
+ /// Renders the specified environmental information and appends it to the specified <see cref="StringBuilder"/>.
+ /// </summary>
+ /// <param name="builder">The <see cref="StringBuilder"/> to append the rendered data to.</param>
+ /// <param name="logEvent">Logging event.</param>
+ protected override void Append(StringBuilder builder, LogEventInfo logEvent)
+ {
+#if !DOCUMENTATION
+ switch (this.Option)
+ {
+ case SilverlightApplicationInfoOption.XapUri:
+ builder.Append(Application.Current.Host.Source);
+ break;
+
+#if !SILVERLIGHT2
+ case SilverlightApplicationInfoOption.IsOutOfBrowser:
+ builder.Append(Application.Current.IsRunningOutOfBrowser ? "1" : "0");
+ break;
+
+ case SilverlightApplicationInfoOption.InstallState:
+ builder.Append(Application.Current.InstallState);
+ break;
+#if !SILVERLIGHT3
+ case SilverlightApplicationInfoOption.HasElevatedPermissions:
+ builder.Append(Application.Current.HasElevatedPermissions ? "1" : "0");
+ break;
+#endif
+
+#endif
+ }
+#endif
+ }
+ }
+}
+
+#endif
@@ -0,0 +1,66 @@
+//
+// Copyright (c) 2004-2010 Jaroslaw Kowalski <jaak@jkowalski.net>
+//
+// All rights reserved.
+//
+// Redistribution and use in source and binary forms, with or without
+// modification, are permitted provided that the following conditions
+// are met:
+//
+// * Redistributions of source code must retain the above copyright notice,
+// this list of conditions and the following disclaimer.
+//
+// * Redistributions in binary form must reproduce the above copyright notice,
+// this list of conditions and the following disclaimer in the documentation
+// and/or other materials provided with the distribution.
+//
+// * Neither the name of Jaroslaw Kowalski nor the names of its
+// contributors may be used to endorse or promote products derived from this
+// software without specific prior written permission.
+//
+// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+// THE POSSIBILITY OF SUCH DAMAGE.
+//
+
+namespace NLog.LayoutRenderers
+{
+ /// <summary>
+ /// Specifies application information to display in ${sl-appinfo} renderer.
+ /// </summary>
+ public enum SilverlightApplicationInfoOption
+ {
+ /// <summary>
+ /// URI of the current application XAP file.
+ /// </summary>
+ XapUri,
+
+#if !SILVERLIGHT2
+ /// <summary>
+ /// Whether application is running out-of-browser.
+ /// </summary>
+ IsOutOfBrowser,
+
+ /// <summary>
+ /// Installed state of an application.
+ /// </summary>
+ InstallState,
+
+#if !SILVERLIGHT3
+ /// <summary>
+ /// Whether application is running with elevated permissions.
+ /// </summary>
+ HasElevatedPermissions,
+#endif
+
+#endif
+ }
+}
View
@@ -42,6 +42,7 @@ namespace NLog
using System.Runtime.CompilerServices;
using System.Text;
using System.Threading;
+ using System.Windows;
using NLog.Common;
using NLog.Config;
using NLog.Internal;
@@ -136,19 +137,26 @@ public LoggingConfiguration Configuration
}
#endif
-#if !SILVERLIGHT
if (this.config == null)
{
foreach (string configFile in GetCandidateFileNames())
{
+#if !SILVERLIGHT
if (File.Exists(configFile))
{
InternalLogger.Debug("Attempting to load config from {0}", configFile);
this.config = new XmlLoggingConfiguration(configFile);
}
+#else
+ Uri configFileUri = new Uri(configFile, UriKind.Relative);
+ if (Application.GetResourceStream(configFileUri) != null)
+ {
+ InternalLogger.Debug("Attempting to load config from {0}", configFile);
+ this.config = new XmlLoggingConfiguration(configFile);
+ }
+#endif
}
}
-#endif
#if !NET_CF && !SILVERLIGHT
if (this.config != null)
@@ -575,7 +583,7 @@ private static IEnumerable<string> GetCandidateFileNames()
yield return Path.Combine(Path.GetDirectoryName(CompactFrameworkHelper.GetExeFileName()), "NLog.config");
yield return typeof(LogFactory).Assembly.GetName().CodeBase + ".nlog";
#elif SILVERLIGHT
- yield break;
+ yield return "NLog.config";
#else
// NLog.config from application directory
yield return Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "NLog.config");
View
@@ -213,6 +213,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
@@ -217,6 +217,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
@@ -225,6 +225,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
@@ -226,6 +226,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
@@ -215,6 +215,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
@@ -211,6 +211,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
@@ -213,6 +213,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
View
@@ -219,6 +219,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
View
@@ -219,6 +219,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
View
@@ -220,6 +220,8 @@
<Compile Include="LayoutRenderers\QpcLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\RegistryLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\ShortDateLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoLayoutRenderer.cs" />
+ <Compile Include="LayoutRenderers\SilverlightApplicationInfoOption.cs" />
<Compile Include="LayoutRenderers\SpecialFolderLayoutRenderer.cs" />
<Compile Include="LayoutRenderers\StackTraceFormat.cs" />
<Compile Include="LayoutRenderers\StackTraceLayoutRenderer.cs" />
Oops, something went wrong.

0 comments on commit 215106a

Please sign in to comment.