Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Go net6 follow up3 #8254

Merged
merged 2 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 4 additions & 13 deletions src/Microsoft.DocAsCode.Common/Loggers/AggregatedLogListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,15 @@ namespace Microsoft.DocAsCode.Common
using System;
using System.Collections.Generic;
using System.Linq;
#if NetCore
using AggregatedList = System.Collections.Generic.SortedDictionary<LogLevel, System.Collections.Generic.List<ILogItem>>;
#else
using AggregatedList = System.Collections.Generic.SortedList<LogLevel, System.Collections.Generic.List<ILogItem>>;
#endif

/// <summary>
/// Replay aggregated log on flushing
/// </summary>
public class AggregatedLogListener : ILoggerListener
{
private readonly LogLevel _threshold;
private readonly ILoggerListener _innerListener;
private readonly AggregatedList _aggregatedList;
private readonly SortedList<LogLevel, List<ILogItem>> _aggregatedList;

public AggregatedLogListener(AggregatedLogListener other) : this(other._threshold)
{
Expand All @@ -28,7 +24,7 @@ public AggregatedLogListener(AggregatedLogListener other) : this(other._threshol
public AggregatedLogListener(LogLevel threshold = LogLevel.Warning)
{
_threshold = threshold;
_aggregatedList = new AggregatedList();
_aggregatedList = new SortedList<LogLevel, List<ILogItem>>();
_innerListener = new ConsoleLogListener();
for (LogLevel level = _threshold; level <= LogLevel.Error; level++)
{
Expand Down Expand Up @@ -87,25 +83,21 @@ private void WriteHeader(BuildStatus status)
default:
break;
}
#if !NetCore

WriteToConsole(message, status);
#endif
}

private void WriteFooter(BuildStatus status)
{
var footer = string.Join(Environment.NewLine, _aggregatedList.Select(s => $"\t{s.Value.Count} {s.Key}(s)"));
#if !NetCore
WriteToConsole(footer, status);
#endif
}

private void WriteLineCore(ILogItem item)
{
_innerListener.WriteLine(item);
}

#if !NetCore
private static void WriteToConsole(string message, BuildStatus status)
{
switch (status)
Expand All @@ -128,7 +120,6 @@ private static void WriteToConsole(string message, ConsoleColor color = ConsoleC
{
ConsoleUtility.WriteLine(message, color);
}
#endif

private static BuildStatus GetBuildStatusFromLogLevel(LogLevel level)
{
Expand Down
4 changes: 1 addition & 3 deletions src/Microsoft.DocAsCode.Common/Loggers/ConsoleLogListener.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !NetCore
namespace Microsoft.DocAsCode.Common
{
using System;
Expand Down Expand Up @@ -72,5 +71,4 @@ private ConsoleColor GetConsoleColor(LogLevel level)
}
}
}
}
#endif
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !NetCore
namespace Microsoft.DocAsCode.Common
{
using System;
Expand Down Expand Up @@ -35,5 +34,4 @@ public void Flush()
Logger.Flush();
}
}
}
#endif
}
2 changes: 0 additions & 2 deletions src/Microsoft.DocAsCode.Common/Loggers/HtmlLogListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public sealed class HtmlLogListener : ILoggerListener
private static readonly Regex EscapeWithEncode = new Regex("&", RegexOptions.Compiled);
private static readonly Regex EscapeWithoutEncode = new Regex(@"&(?!#?\w+;)", RegexOptions.Compiled);

#if !NetCore
public HtmlLogListener(string reportPath)
{
var dir = Path.GetDirectoryName(reportPath);
Expand All @@ -29,7 +28,6 @@ public HtmlLogListener(string reportPath)
_writer = new StreamWriter(reportPath, true);
WriteCommonHeader();
}
#endif

public HtmlLogListener(StreamWriter writer)
{
Expand Down
18 changes: 0 additions & 18 deletions src/Microsoft.DocAsCode.Common/Loggers/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -135,41 +135,25 @@ public static void Log(LogLevel level, string message, string phase = null, stri
{
Log(new LogItem
{
#if NetCore
File = file,
#else
File = file ?? LoggerFileScope.GetFileName(),
#endif
Line = line,
LogLevel = level,
Message = message,
Code = code,
#if NetCore
Phase = phase,
#else
Phase = phase ?? LoggerPhaseScope.GetPhaseName(),
#endif
});
}

public static ILogItem GetLogItem(LogLevel level, string message, string phase = null, string file = null, string line = null, string code = null)
{
return new LogItem
{
#if NetCore
File = file,
#else
File = file ?? LoggerFileScope.GetFileName(),
#endif
Line = line,
LogLevel = level,
Message = message,
Code = code,
#if NetCore
Phase = phase,
#else
Phase = phase ?? LoggerPhaseScope.GetPhaseName(),
#endif
};
}

Expand Down Expand Up @@ -248,9 +232,7 @@ public static void Flush()
_asyncListener.Flush();
}

#if !NetCore
[Serializable]
#endif
private class LogItem : ILogItem
{
public string File { get; set; }
Expand Down
4 changes: 1 addition & 3 deletions src/Microsoft.DocAsCode.Common/Loggers/LoggerFileScope.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !NetCore
namespace Microsoft.DocAsCode.Common
{
using System;
Expand Down Expand Up @@ -54,5 +53,4 @@ private sealed class CapturedLoggerFileScope
public string FileName { get; } = GetFileName();
}
}
}
#endif
}
4 changes: 1 addition & 3 deletions src/Microsoft.DocAsCode.Common/Loggers/PerformanceScope.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.

#if !NetCore
namespace Microsoft.DocAsCode.Common
{
using System;
Expand Down Expand Up @@ -49,5 +48,4 @@ private static string GetContent(string content, TimeSpan span)
return $"Completed {content} in {span.TotalMilliseconds} milliseconds.";
}
}
}
#endif
}
17 changes: 4 additions & 13 deletions src/Microsoft.DocAsCode.Common/Loggers/ReplayLogListener.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,15 @@ namespace Microsoft.DocAsCode.Common
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Linq;
#if NetCore
using ReplayList = System.Collections.Generic.SortedDictionary<LogLevel, System.Collections.Generic.List<ILogItem>>;
#else
using ReplayList = System.Collections.Generic.SortedList<LogLevel, System.Collections.Generic.List<ILogItem>>;
#endif

/// <summary>
/// Replay log on flushing.
/// </summary>
[Obsolete]
public class ReplayLogListener : ILoggerListener
{
private readonly LogLevel _replayLevel;
private readonly ReplayList _replayList;
private readonly SortedList<LogLevel, List<ILogItem>> _replayList;
private ImmutableArray<ILoggerListener> _listeners =
ImmutableArray<ILoggerListener>.Empty;

Expand All @@ -28,7 +24,7 @@ public class ReplayLogListener : ILoggerListener
public ReplayLogListener(LogLevel replayLevel = LogLevel.Warning)
{
_replayLevel = replayLevel;
_replayList = new ReplayList();
_replayList = new SortedList<LogLevel, List<ILogItem>>();
for (LogLevel level = replayLevel; level <= LogLevel.Error; level++)
{
_replayList.Add(level, new List<ILogItem>());
Expand Down Expand Up @@ -102,17 +98,14 @@ private void WriteHeader(BuildStatus status)
default:
break;
}
#if !NetCore

WriteToConsole(message, status);
#endif
}

private void WriteFooter(BuildStatus status)
{
var footer = string.Join(Environment.NewLine, _replayList.Select(s => $"\t{s.Value.Count} {s.Key}(s)"));
#if !NetCore
WriteToConsole(footer, status);
#endif
}

private void WriteLineCore(ILogItem item)
Expand All @@ -123,7 +116,6 @@ private void WriteLineCore(ILogItem item)
}
}

#if !NetCore
private static void WriteToConsole(string message, BuildStatus status)
{
switch (status)
Expand All @@ -144,7 +136,6 @@ private static void WriteToConsole(string message, ConsoleColor color = ConsoleC
{
ConsoleUtility.WriteLine(message, color);
}
#endif

private static BuildStatus GetBuildStatusFromLogLevel(LogLevel level)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ namespace Microsoft.DocAsCode.YamlSerialization.ObjectGraphTraversalStrategies
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
#if !NetCore
using System.Globalization;
#endif
using System.Reflection;
using System.Reflection.Emit;

Expand Down
8 changes: 8 additions & 0 deletions src/docfx/SubCommands/BuildCommand.cs
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,7 @@ private void BuildDocument(string baseDirectory, string outputDirectory)
}
}

#if NET472
private static void BuildDocumentWithPlugin(BuildJsonConfig config, TemplateManager manager, string baseDirectory, string outputDirectory, string applicationBaseDirectory, string pluginDirectory, string templateDirectory)
{
AppDomain builderDomain = null;
Expand Down Expand Up @@ -531,6 +532,13 @@ private static void BuildDocumentWithPlugin(BuildJsonConfig config, TemplateMana
}
}
}
#else
private static void BuildDocumentWithPlugin(BuildJsonConfig config, TemplateManager manager, string baseDirectory, string outputDirectory, string applicationBaseDirectory, string pluginDirectory, string templateDirectory)
{
var wrapper = new DocumentBuilderWrapper(config, manager, baseDirectory, outputDirectory, pluginDirectory, new CrossAppDomainListener(), templateDirectory);
wrapper.BuildDocument();
}
#endif

#endregion
}
Expand Down
9 changes: 7 additions & 2 deletions src/docfx/SubCommands/DocumentBuilderWrapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ namespace Microsoft.DocAsCode.SubCommands
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.Remoting.Lifetime;
using System.Reflection;
using System.Threading;

Expand Down Expand Up @@ -67,15 +66,19 @@ public DocumentBuilderWrapper(

public void BuildDocument()
{
var sponsor = new ClientSponsor();
#if NET472
var sponsor = new System.Runtime.Remoting.Lifetime.ClientSponsor();
#endif
EnvironmentContext.SetBaseDirectory(_baseDirectory);
EnvironmentContext.SetGitFeaturesDisabled(_disableGitFeatures);
EnvironmentContext.SetVersion(_version);
if (_listener != null)
{
Logger.LogLevelThreshold = _logLevel;
Logger.RegisterListener(_listener);
#if NET472
sponsor.Register(_listener);
#endif
}
try
{
Expand Down Expand Up @@ -106,7 +109,9 @@ public void BuildDocument()
}
finally
{
#if NET472
sponsor.Close();
#endif
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/docfx/docfx.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="../Shared/base.props" />
<Import Project="../Shared/base.net.props" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<Description>Generates documentation directly from source code and MarkDown files</Description>
Expand Down