Skip to content

Commit

Permalink
UWP without System.Threading.Thread, System.Console and System.Diagno…
Browse files Browse the repository at this point in the history
…stics.Trace
  • Loading branch information
snakefoot committed Dec 2, 2017
1 parent 46d55f4 commit c5e71f7
Show file tree
Hide file tree
Showing 81 changed files with 358 additions and 306 deletions.
2 changes: 1 addition & 1 deletion build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ $versionProduct = $versionPrefix;
if (-Not $versionSuffix.Equals(""))
{ $versionProduct = $versionProduct + "-" + $versionSuffix }

msbuild /t:Restore,Pack .\src\NLog\ /p:targetFrameworks='"net45;net40-client;net35;netstandard1.5;netstandard2.0;sl4;sl5;wp8;monoandroid44;xamarinios10"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:PackageOutputPath=..\..\artifacts /verbosity:minimal
msbuild /t:Restore,Pack .\src\NLog\ /p:targetFrameworks='"net45;net40-client;net35;netstandard1.5;netstandard2.0;uap10.0;sl4;sl5;wp8;monoandroid44;xamarinios10"' /p:VersionPrefix=$versionPrefix /p:VersionSuffix=$versionSuffix /p:FileVersion=$versionFile /p:ProductVersion=$versionProduct /p:Configuration=Release /p:IncludeSymbols=true /p:PackageOutputPath=..\..\artifacts /verbosity:minimal
if (-Not $LastExitCode -eq 0)
{ exit $LastExitCode }

Expand Down
12 changes: 9 additions & 3 deletions src/NLog.Wcf/NLog.Wcf.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle>

<TargetFrameworks>netstandard1.5;netstandard2.0</TargetFrameworks>
<TargetFrameworks>netstandard1.3;netstandard1.5;netstandard2.0</TargetFrameworks>

<Title>NLog.WCF for .NET Standard</Title>
<Company>NLog</Company>
Expand Down Expand Up @@ -33,10 +33,16 @@
<GenerateDocumentationFile>true</GenerateDocumentationFile>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.3' ">
<Title>NLog.Wcf for NetStandard 1.3</Title>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<DefineConstants>$(DefineConstants);NET4_5;NETSTANDARD;NETSTANDARD1_0;WCF_SUPPORTED</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' ">
<Title>NLog.Wcf for NetStandard 1.5</Title>
<NetStandardImplicitPackageVersion>1.6.0</NetStandardImplicitPackageVersion>
<DefineConstants>$(DefineConstants);NET4_5;NETSTANDARD;NETSTANDARD1_5;WCF_SUPPORTED</DefineConstants>
<DefineConstants>$(DefineConstants);NET4_5;NETSTANDARD;NETSTANDARD1_0;WCF_SUPPORTED</DefineConstants>
</PropertyGroup>

<PropertyGroup Condition=" '$(TargetFramework)' == 'netstandard2.0' ">
Expand Down Expand Up @@ -71,7 +77,7 @@
<ProjectReference Include="..\NLog\NLog.csproj" />
</ItemGroup>

<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' ">
<ItemGroup Condition=" '$(TargetFramework)' == 'netstandard1.5' or '$(TargetFramework)' == 'netstandard1.3' ">
<PackageReference Include="System.ServiceModel.Duplex" Version="4.0.1" />
<PackageReference Include="System.ServiceModel.Http" Version="4.1.0" />
<PackageReference Include="System.ServiceModel.NetTcp" Version="4.1.0" />
Expand Down
2 changes: 1 addition & 1 deletion src/NLog.Wcf/Properties/AssemblyInfo.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
#endif
#if !SILVERLIGHT4
[assembly: AllowPartiallyTrustedCallers]
#if !NET3_5 && !MONO_2_0 && !SILVERLIGHT5 && !__IOS__ && !__ANDROID__ && !WINDOWS_PHONE && !NETSTANDARD1_5
#if !NET3_5 && !MONO_2_0 && !SILVERLIGHT5 && !__IOS__ && !__ANDROID__ && !WINDOWS_PHONE && !NETSTANDARD1_0
[assembly: SecurityRules(SecurityRuleSet.Level1)]
#endif
#endif
34 changes: 30 additions & 4 deletions src/NLog/Common/AsyncHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,40 @@ namespace NLog.Common
using System.Collections.Generic;
using System.Text;
using System.Threading;
using Internal;
using NLog.Internal;

/// <summary>
/// Helpers for asynchronous operations.
/// </summary>
public static class AsyncHelpers
{
internal static int GetManagedThreadId()
{
#if WINDOWS_UWP
return System.Environment.CurrentManagedThreadId;
#else
return Thread.CurrentThread.ManagedThreadId;
#endif
}

internal static void StartAsyncTask(Action<object> action, object state)
{
#if NET4_0 || NET4_5 || NETSTANDARD
System.Threading.Tasks.Task.Factory.StartNew(action, state, CancellationToken.None, System.Threading.Tasks.TaskCreationOptions.None, System.Threading.Tasks.TaskScheduler.Default);
#else
ThreadPool.QueueUserWorkItem(new WaitCallback(action), state);
#endif
}

internal static void WaitForDelay(TimeSpan delay)
{
#if WINDOWS_UWP
System.Threading.Tasks.Task.Delay(delay).Wait();
#else
Thread.Sleep(delay);
#endif
}

/// <summary>
/// Iterates over all items in the given collection and runs the specified action
/// in sequence (each action executes only after the preceding one has completed without an error).
Expand Down Expand Up @@ -202,8 +229,7 @@ public static void ForEachItemInParallel<T>(IEnumerable<T> values, AsyncContinua
foreach (T item in items)
{
T itemCopy = item;

ThreadPool.QueueUserWorkItem(s =>
StartAsyncTask(s =>
{
try
{
Expand All @@ -217,7 +243,7 @@ public static void ForEachItemInParallel<T>(IEnumerable<T> values, AsyncContinua
throw; // Throwing exceptions here will crash the entire application (.NET 2.0 behavior)
}
}
});
}, null);
}
}

Expand Down
19 changes: 13 additions & 6 deletions src/NLog/Common/InternalLogger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ public static void Reset()

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__
/// <summary>
/// Gets or sets a value indicating whether internal messages should be written to the <see cref="System.Diagnostics.Trace"/>.
/// Gets or sets a value indicating whether internal messages should be written to the <see cref="System.Diagnostics"/>.Trace
/// </summary>
public static bool LogToTrace { get; set; }
#endif
Expand Down Expand Up @@ -257,10 +257,13 @@ private static void Write([CanBeNull]Exception ex, LogLevel level, string messag

WriteToLogFile(msg);
WriteToTextWriter(msg);

#if !WINDOWS_UWP
WriteToConsole(msg);
WriteToErrorConsole(msg);
#endif

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__
#if !SILVERLIGHT && !__IOS__ && !__ANDROID__ && !WINDOWS_UWP
WriteToTrace(msg);
#endif
}
Expand Down Expand Up @@ -362,7 +365,7 @@ private static void WriteToLogFile(string message)
{
textWriter.WriteLine(message);
}
}
}
}

/// <summary>
Expand All @@ -387,6 +390,7 @@ private static void WriteToTextWriter(string message)
}
}

#if !WINDOWS_UWP
/// <summary>
/// Write internal messages to the <see cref="System.Console"/>.
/// </summary>
Expand All @@ -407,7 +411,9 @@ private static void WriteToConsole(string message)
Console.WriteLine(message);
}
}
#endif

#if !WINDOWS_UWP
/// <summary>
/// Write internal messages to the <see cref="System.Console.Error"/>.
/// </summary>
Expand All @@ -423,14 +429,15 @@ private static void WriteToErrorConsole(string message)
return;
}


lock (LockObject)
{
Console.Error.WriteLine(message);
}

}
#endif

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__
#if !SILVERLIGHT && !__IOS__ && !__ANDROID__ && !WINDOWS_UWP
/// <summary>
/// Write internal messages to the <see cref="System.Diagnostics.Trace"/>.
/// </summary>
Expand Down Expand Up @@ -460,7 +467,7 @@ public static void LogAssemblyVersion(Assembly assembly)
{
try
{
#if SILVERLIGHT || __IOS__ || __ANDROID__ || NETSTANDARD
#if SILVERLIGHT || __IOS__ || __ANDROID__ || NETSTANDARD1_0
Info(assembly.FullName);
#else
var fileVersionInfo = System.Diagnostics.FileVersionInfo.GetVersionInfo(assembly.Location);
Expand Down
4 changes: 2 additions & 2 deletions src/NLog/Conditions/ConditionEvaluationException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace NLog.Conditions
/// <summary>
/// Exception during evaluation of condition expression.
/// </summary>
#if !SILVERLIGHT && !NETSTANDARD1_5
#if !SILVERLIGHT && !NETSTANDARD1_0
[Serializable]
#endif
public class ConditionEvaluationException : Exception
Expand Down Expand Up @@ -69,7 +69,7 @@ public ConditionEvaluationException(string message, Exception innerException)
{
}

#if !SILVERLIGHT && !NETSTANDARD1_5
#if !SILVERLIGHT && !NETSTANDARD1_0
/// <summary>
/// Initializes a new instance of the <see cref="ConditionEvaluationException" /> class.
/// </summary>
Expand Down
4 changes: 2 additions & 2 deletions src/NLog/Conditions/ConditionParseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ namespace NLog.Conditions
/// <summary>
/// Exception during parsing of condition expression.
/// </summary>
#if !SILVERLIGHT && !NETSTANDARD1_5
#if !SILVERLIGHT && !NETSTANDARD1_0
[Serializable]
#endif
public class ConditionParseException : Exception
Expand Down Expand Up @@ -69,7 +69,7 @@ public ConditionParseException(string message, Exception innerException)
{
}

#if !SILVERLIGHT && !NETSTANDARD1_5
#if !SILVERLIGHT && !NETSTANDARD1_0
/// <summary>
/// Initializes a new instance of the <see cref="ConditionParseException" /> class.
/// </summary>
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Conditions/ConditionRelationalExpression.cs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ protected override object EvaluateNode(LogEventInfo context)
/// <returns>Result of the given relational operator.</returns>
private static object Compare(object leftValue, object rightValue, ConditionRelationalOperator relationalOperator)
{
#if !NETSTANDARD1_5
#if !NETSTANDARD1_0
StringComparer comparer = StringComparer.InvariantCulture;
#else
var comparer = new System.Collections.Comparer(CultureInfo.InvariantCulture);
Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Config/AdvancedAttribute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ namespace NLog.Config
/// default in generated documentation.
/// </summary>
[AttributeUsage(AttributeTargets.Property)]
#if NET4_0 || NET4_5 && !NETSTANDARD1_5
#if NET4_0 || NET4_5 && !NETSTANDARD1_0
[System.Diagnostics.CodeAnalysis.ExcludeFromCodeCoverage]
#endif
public sealed class AdvancedAttribute : Attribute
Expand Down
18 changes: 9 additions & 9 deletions src/NLog/Config/ConfigurationItemFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ namespace NLog.Config
using System;
using System.Collections.Generic;
using System.Reflection;
using Conditions;
using Filters;
using Internal;
using LayoutRenderers;
using Layouts;
using Targets;
using Time;
using NLog.Conditions;
using NLog.Filters;
using NLog.Internal;
using NLog.LayoutRenderers;
using NLog.Layouts;
using NLog.Targets;
using NLog.Time;

/// <summary>
/// Provides registration information for named items (targets, layouts, layout renderers, etc.) managed by NLog.
Expand Down Expand Up @@ -367,7 +367,7 @@ private static ConfigurationItemFactory BuildDefaultFactory()
var factory = new ConfigurationItemFactory(nlogAssembly);
factory.RegisterExtendedItems();

#if !SILVERLIGHT
#if !SILVERLIGHT && !WINDOWS_UWP
try
{
var assemblyLocation = GetAssemblyFileLocation(nlogAssembly);
Expand Down Expand Up @@ -448,7 +448,7 @@ private static ConfigurationItemFactory BuildDefaultFactory()
return factory;
}

#if !SILVERLIGHT
#if !SILVERLIGHT && !WINDOWS_UWP
private static string GetAssemblyFileLocation(Assembly assembly)
{
try
Expand Down
4 changes: 2 additions & 2 deletions src/NLog/Config/InstallationContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace NLog.Config
/// </summary>
public sealed class InstallationContext : IDisposable
{
#if !SILVERLIGHT
#if !SILVERLIGHT && !WINDOWS_UWP
/// <summary>
/// Mapping between log levels and console output colors.
/// </summary>
Expand Down Expand Up @@ -195,7 +195,7 @@ private void Log(LogLevel logLevel, [Localizable(false)] string message, object[
message = string.Format(CultureInfo.InvariantCulture, message, arguments);
}

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__
#if !SILVERLIGHT && !__IOS__ && !__ANDROID__ && !WINDOWS_UWP
var oldColor = Console.ForegroundColor;
Console.ForegroundColor = logLevel2ConsoleColor[logLevel];

Expand Down
2 changes: 1 addition & 1 deletion src/NLog/Config/LoggingConfigurationReloadedEventArgs.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
// THE POSSIBILITY OF SUCH DAMAGE.
//

#if !SILVERLIGHT && !__IOS__ && !__ANDROID__
#if !SILVERLIGHT && !__IOS__ && !__ANDROID__ && !WINDOWS_UWP

namespace NLog.Config
{
Expand Down
2 changes: 2 additions & 0 deletions src/NLog/Config/SimpleConfigurator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ namespace NLog.Config
/// </summary>
public static class SimpleConfigurator
{
#if !WINDOWS_UWP
/// <summary>
/// Configures NLog for console logging so that all messages above and including
/// the <see cref="NLog.LogLevel.Info"/> level are output to the console.
Expand All @@ -66,6 +67,7 @@ public static void ConfigureForConsoleLogging(LogLevel minLevel)
config.AddRule(minLevel, LogLevel.MaxLevel, consoleTarget, "*");
LogManager.Configuration = config;
}
#endif

/// <summary>
/// Configures NLog for to log to the specified target so that all messages
Expand Down
6 changes: 4 additions & 2 deletions src/NLog/Config/XmlLoggingConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1021,12 +1021,14 @@ private void ParseExtensionsElement(NLogXmlElement extensionsElement, string bas
}
}

#if !WINDOWS_UWP
string assemblyFile = addElement.GetOptionalAttribute("assemblyFile", null);
if (assemblyFile != null)
{
ParseExtensionWithAssemblyFle(baseDirectory, assemblyFile, prefix);
continue;
}
#endif

string assemblyName = addElement.GetOptionalAttribute("assembly", null);
if (assemblyName != null)
Expand Down Expand Up @@ -1061,6 +1063,7 @@ private void ParseExtensionWithAssembly(string assemblyName, string prefix)
}
}

#if !WINDOWS_UWP
private void ParseExtensionWithAssemblyFle(string baseDirectory, string assemblyFile, string prefix)
{
try
Expand All @@ -1084,9 +1087,8 @@ private void ParseExtensionWithAssemblyFle(string baseDirectory, string assembly
throw configException;
}
}

return;
}
#endif

private void ParseIncludeElement(NLogXmlElement includeElement, string baseDirectory, bool autoReloadDefault)
{
Expand Down
4 changes: 3 additions & 1 deletion src/NLog/Internal/AssemblyHelpers.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ namespace NLog.Internal
/// </summary>
internal static class AssemblyHelpers
{
#if !WINDOWS_UWP
/// <summary>
/// Load from url
/// </summary>
Expand Down Expand Up @@ -79,6 +80,7 @@ public static Assembly LoadFromPath(string assemblyFileName, string baseDirector
return asm;
#endif
}
#endif

/// <summary>
/// Load from url
Expand All @@ -89,7 +91,7 @@ public static Assembly LoadFromName(string assemblyName)
{
InternalLogger.Info("Loading assembly: {0}", assemblyName);

#if NETSTANDARD1_5 || WINDOWS_PHONE
#if NETSTANDARD1_0 || WINDOWS_PHONE
var name = new AssemblyName(assemblyName);
return Assembly.Load(name);
#elif SILVERLIGHT && !WINDOWS_PHONE
Expand Down
Loading

0 comments on commit c5e71f7

Please sign in to comment.