Skip to content

Commit

Permalink
NetStandard1.3 without System.Threading.Thread and System.Console (WI…
Browse files Browse the repository at this point in the history
…NDOWS_UWP)
  • Loading branch information
snakefoot committed Dec 2, 2017
1 parent 46d55f4 commit 17c4ac5
Show file tree
Hide file tree
Showing 79 changed files with 930 additions and 290 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.3;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
if (-Not $LastExitCode -eq 0)
{ exit $LastExitCode }

Expand Down
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 !NETSTANDARD || NETSTANDARD1_3PLUS
return Thread.CurrentThread.ManagedThreadId;
#else
return System.Environment.CurrentManagedThreadId;
#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
10 changes: 5 additions & 5 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 @@ -260,7 +260,7 @@ private static void Write([CanBeNull]Exception ex, LogLevel level, string messag
WriteToConsole(msg);
WriteToErrorConsole(msg);

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

/// <summary>
Expand Down Expand Up @@ -430,7 +430,7 @@ private static void WriteToErrorConsole(string message)

}

#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 +460,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
Loading

0 comments on commit 17c4ac5

Please sign in to comment.