提交 ba582bdf 编写于 作者: C CyrusNajmabadi 提交者: GitHub

Merge pull request #14057 from CyrusNajmabadi/asyncLogginc

Make the logging service async.  That way we can move package update out of proc while still logginc to the VS log in a non-blocking fashion
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information. // Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System; using System;
using System.Threading.Tasks;
namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch
{ {
...@@ -9,7 +10,7 @@ namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch ...@@ -9,7 +10,7 @@ namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch
/// </summary> /// </summary>
internal interface ILogService internal interface ILogService
{ {
void LogException(Exception e, string text); Task LogExceptionAsync(Exception e, string text);
void LogInfo(string text); Task LogInfoAsync(string text);
} }
} }
\ No newline at end of file
...@@ -2,7 +2,9 @@ ...@@ -2,7 +2,9 @@
using System; using System;
using Microsoft.CodeAnalysis.Editor.Shared.Utilities; using Microsoft.CodeAnalysis.Editor.Shared.Utilities;
using Roslyn.Utilities;
using Microsoft.VisualStudio.Shell.Interop; using Microsoft.VisualStudio.Shell.Interop;
using System.Threading.Tasks;
namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch namespace Microsoft.VisualStudio.LanguageServices.SymbolSearch
{ {
...@@ -17,18 +19,24 @@ public LogService(IVsActivityLog activityLog) ...@@ -17,18 +19,24 @@ public LogService(IVsActivityLog activityLog)
_activityLog = activityLog; _activityLog = activityLog;
} }
public void LogInfo(string text) public Task LogInfoAsync(string text)
{ {
Log(text, __ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION); return LogAsync(text, __ACTIVITYLOG_ENTRYTYPE.ALE_INFORMATION);
} }
public void LogException(Exception e, string text) public Task LogExceptionAsync(Exception e, string text)
{ {
Log(text + ". " + e.ToString(), __ACTIVITYLOG_ENTRYTYPE.ALE_ERROR); return LogAsync(text + ". " + e.ToString(), __ACTIVITYLOG_ENTRYTYPE.ALE_ERROR);
} }
private void Log(string text, __ACTIVITYLOG_ENTRYTYPE type) private Task LogAsync(string text, __ACTIVITYLOG_ENTRYTYPE type)
{ {
Log(text, type);
return SpecializedTasks.EmptyTask;
}
private void Log(string text, __ACTIVITYLOG_ENTRYTYPE type)
{
if (!this.IsForeground()) if (!this.IsForeground())
{ {
this.InvokeBelowInputPriority(() => Log(text, type)); this.InvokeBelowInputPriority(() => Log(text, type));
......
...@@ -13,6 +13,7 @@ Imports Microsoft.Internal.VisualStudio.Shell.Interop ...@@ -13,6 +13,7 @@ Imports Microsoft.Internal.VisualStudio.Shell.Interop
Imports Microsoft.VisualStudio.LanguageServices.SymbolSearch Imports Microsoft.VisualStudio.LanguageServices.SymbolSearch
Imports Moq Imports Moq
Imports Roslyn.Test.Utilities Imports Roslyn.Test.Utilities
Imports Roslyn.Utilities
Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SymbolSearch Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SymbolSearch
Public Class SymbolSearchServiceTests Public Class SymbolSearchServiceTests
...@@ -817,11 +818,13 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SymbolSearch ...@@ -817,11 +818,13 @@ Namespace Microsoft.VisualStudio.LanguageServices.UnitTests.SymbolSearch
Private Sub New() Private Sub New()
End Sub End Sub
Public Sub LogException(e As Exception, text As String) Implements ILogService.LogException Public Function LogExceptionAsync(e As Exception, text As String) As Task Implements ILogService.LogExceptionAsync
End Sub Return SpecializedTasks.EmptyTask
End Function
Public Sub LogInfo(text As String) Implements ILogService.LogInfo Public Function LogInfoAsync(text As String) As Task Implements ILogService.LogInfoAsync
End Sub Return SpecializedTasks.EmptyTask
End Function
End Class End Class
End Class End Class
End Namespace End Namespace
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册