Skip to content

Commit ab5ca43

Browse files
lbussellCopilot
andauthored
Migrate to Microsoft.Extensions.Logging (#1968)
Part 1/2 of #1908 - Migrate to M.E.Logging. - Removed our ad-hoc logger setup. Use the default M.E.Logging setup provided by M.E.Hosting instead. - All classes/serivces now take `ILogger<T> logger` parameters and have a private `_logger` field. Everything is [Info] level right now. We can adjust later as we go. TODO (before merging): - [ ] Ensure Azure Pipelines logging directives still work - [ ] Remove instances of protected loggers in favor of private instead --------- Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 01bcfe5 commit ab5ca43

80 files changed

Lines changed: 660 additions & 652 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/ImageBuilder.Tests/AnnotateEolDigestsCommandTests.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,11 @@
1111
using Microsoft.DotNet.ImageBuilder.Models.Annotations;
1212
using Microsoft.DotNet.ImageBuilder.Models.Oci;
1313
using Microsoft.DotNet.ImageBuilder.Tests.Helpers;
14+
using Microsoft.Extensions.Logging;
1415
using Moq;
1516
using Newtonsoft.Json;
16-
using Xunit;
1717
using Xunit.Abstractions;
18+
using Xunit;
1819

1920
namespace Microsoft.DotNet.ImageBuilder.Tests
2021
{
@@ -51,9 +52,9 @@ public async Task AnnotateEolDigestsCommand_AnnotationSuccess()
5152

5253
Manifest manifest;
5354
lifecycleMetadataServiceMock.Verify(
54-
o => o.AnnotateEolDigest("digest1", _globalDate, It.IsAny<ILoggerService>(), It.IsAny<bool>(), out manifest));
55+
o => o.AnnotateEolDigest("digest1", _globalDate, It.IsAny<ILogger>(), It.IsAny<bool>(), out manifest));
5556
lifecycleMetadataServiceMock.Verify(
56-
o => o.AnnotateEolDigest("digest2", _specificDigestDate, It.IsAny<ILoggerService>(), It.IsAny<bool>(), out manifest));
57+
o => o.AnnotateEolDigest("digest2", _specificDigestDate, It.IsAny<ILogger>(), It.IsAny<bool>(), out manifest));
5758

5859
string[] expectedAnnotationDigests =
5960
[
@@ -106,7 +107,7 @@ public async Task AnnotateEolDigestsCommand_CheckAnnotations_AlreadyAnnotated_No
106107

107108
Manifest manifest;
108109
lifecycleMetadataServiceMock.Verify(
109-
o => o.AnnotateEolDigest(It.IsAny<string>(), It.IsAny<DateOnly>(), It.IsAny<ILoggerService>(), It.IsAny<bool>(), out manifest),
110+
o => o.AnnotateEolDigest(It.IsAny<string>(), It.IsAny<DateOnly>(), It.IsAny<ILogger>(), It.IsAny<bool>(), out manifest),
110111
Times.Never());
111112
}
112113

@@ -128,7 +129,7 @@ public async Task AnnotateEolDigestsCommand_CheckAnnotations_AlreadyAnnotated_Ma
128129

129130
Manifest manifest;
130131
lifecycleMetadataServiceMock.Verify(
131-
o => o.AnnotateEolDigest(It.IsAny<string>(), It.IsAny<DateOnly>(), It.IsAny<ILoggerService>(), It.IsAny<bool>(), out manifest),
132+
o => o.AnnotateEolDigest(It.IsAny<string>(), It.IsAny<DateOnly>(), It.IsAny<ILogger>(), It.IsAny<bool>(), out manifest),
132133
Times.Never());
133134
}
134135

@@ -152,7 +153,7 @@ private AnnotateEolDigestsCommand InitializeCommand(
152153
string eolDigestsListPath = Path.Combine(tempFolderContext.Path, "eol-digests.json");
153154
File.WriteAllText(eolDigestsListPath, JsonConvert.SerializeObject(eolAnnotations));
154155

155-
Mock<ILoggerService> loggerServiceMock = new();
156+
Mock<ILogger<AnnotateEolDigestsCommand>> loggerServiceMock = new();
156157
lifecycleMetadataServiceMock = CreateLifecycleMetadataServiceMock(digestAlreadyAnnotated, digestAnnotationIsSuccessful, useNonMatchingDate);
157158
AnnotateEolDigestsCommand command = new(
158159
loggerServiceMock.Object,
@@ -177,7 +178,7 @@ private Mock<ILifecycleMetadataService> CreateLifecycleMetadataServiceMock(bool
177178
};
178179

179180
lifecycleMetadataServiceMock
180-
.Setup(o => o.AnnotateEolDigest(It.Is<string>(digest => digest.Contains("digest1")), It.IsAny<DateOnly>(), It.IsAny<ILoggerService>(), It.IsAny<bool>(), out digest1Annotation))
181+
.Setup(o => o.AnnotateEolDigest(It.Is<string>(digest => digest.Contains("digest1")), It.IsAny<DateOnly>(), It.IsAny<ILogger>(), It.IsAny<bool>(), out digest1Annotation))
181182
.Returns(digestAnnotationIsSuccessful);
182183

183184
Manifest digest2Annotation = new()
@@ -186,7 +187,7 @@ private Mock<ILifecycleMetadataService> CreateLifecycleMetadataServiceMock(bool
186187
};
187188

188189
lifecycleMetadataServiceMock
189-
.Setup(o => o.AnnotateEolDigest(It.Is<string>(digest => digest.Contains("digest2")), It.IsAny<DateOnly>(), It.IsAny<ILoggerService>(), It.IsAny<bool>(), out digest2Annotation))
190+
.Setup(o => o.AnnotateEolDigest(It.Is<string>(digest => digest.Contains("digest2")), It.IsAny<DateOnly>(), It.IsAny<ILogger>(), It.IsAny<bool>(), out digest2Annotation))
190191
.Returns(digestAnnotationIsSuccessful);
191192

192193
return lifecycleMetadataServiceMock;
@@ -213,7 +214,7 @@ private static void SetupIsDigestAnnotatedForEolMethod(Mock<ILifecycleMetadataSe
213214
}
214215

215216
lifecycleMetadataServiceMock
216-
.Setup(o => o.IsDigestAnnotatedForEol(digest, It.IsAny<ILoggerService>(), It.IsAny<bool>(), out manifest))
217+
.Setup(o => o.IsDigestAnnotatedForEol(digest, It.IsAny<ILogger>(), It.IsAny<bool>(), out manifest))
217218
.Returns(digestAlreadyAnnotated);
218219
}
219220
}

0 commit comments

Comments
 (0)