Skip to content

Commit 1546dc3

Browse files
committed
Fix: exceptions not printing in Output window.
1 parent c14d6d9 commit 1546dc3

3 files changed

Lines changed: 31 additions & 4 deletions

File tree

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
namespace XrmTools.Tests.Logging;
2+
using System;
3+
using FluentAssertions;
4+
using Xunit;
5+
using XrmTools.Logging.Compatibility;
6+
7+
public class OutputLoggerTests
8+
{
9+
[Fact]
10+
public void AppendException_Should_Include_Exception_Details()
11+
{
12+
var logRecord = "[Error] TestCategory: Failed to register plugin assembly.";
13+
var exception = new InvalidOperationException("Boom");
14+
15+
var result = OutputLogger.AppendException(logRecord, exception);
16+
17+
result.Should().StartWith(logRecord + Environment.NewLine);
18+
result.Should().Contain(exception.ToString());
19+
}
20+
}

src/XrmTools/Logging/OutputLogger.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,12 +46,19 @@ public void Log<TState>(LogLevel logLevel, EventId eventId, TState state, Except
4646
logRecord = $"{string.Join(" => ", scopeInfo)}: {logRecord}";
4747
}
4848

49-
if (exception != null && logLevel <= LogLevel.Debug)
49+
logRecord = AppendException(logRecord, exception);
50+
51+
outputLoggerService.OutputString(logRecord + Environment.NewLine);
52+
}
53+
54+
internal static string AppendException(string logRecord, Exception? exception)
55+
{
56+
if (exception is null)
5057
{
51-
logRecord += Environment.NewLine + exception.ToString();
58+
return logRecord;
5259
}
5360

54-
outputLoggerService.OutputString(logRecord + Environment.NewLine);
61+
return logRecord + Environment.NewLine + exception;
5562
}
5663

5764
private class Scope(object state) : IDisposable

src/XrmTools/Services/PluginRegistrationService.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -395,7 +395,7 @@ public async Task<PluginRegistrationResult> RegisterAsync(RegistrationInput inpu
395395
catch (Exception ex)
396396
{
397397
_log.LogError(ex, "An error occurred while registering steps/custom APIs after package upload.");
398-
return PluginRegistrationResult.Failure("Plugin registration failed during follow-up registration of steps/custom APIs.");
398+
return PluginRegistrationResult.Failure("Plugin registration failed during follow-up registration of steps/custom APIs. Please check the Output window for more details.");
399399
}
400400
}
401401

0 commit comments

Comments
 (0)