Skip to content

Commit 619b387

Browse files
GH-152 - Use ILogger instead of IEventLogService in the main branch (#154)
* GH-149 :: Update main branch to 30.11.1 * GH-152 :: Replace IEventLogService with ILogger * GH-152 :: Adjust logging levels * GH-152 :: Add event IDs for logging * GH-152 :: adjust capitalization in readme file when referring to repo vs guides
1 parent 1cdfd0a commit 619b387

File tree

4 files changed

+32
-24
lines changed

4 files changed

+32
-24
lines changed

README.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
# Xperience by Kentico Training Guides starter repository
1+
# Xperience by Kentico *Training guides* starter repository
22

3-
This repository is the starting point for the [Xperience by Kentico technical Training Guides](https://docs.kentico.com/guides/development). Use this branch to follow along with the Training guides.
3+
This repository is the starting point for the [Xperience by Kentico technical training guides](https://docs.kentico.com/guides/development). Use this branch to follow along with the training guides.
44

55
> [!NOTE]
66
> This repository uses Xperience by Kentico version **30.11.1**.
77
8-
The [finished branch](https://github.com/Kentico/xperience-by-kentico-training-guides/tree/finished) contains the cumulative results of the Training guides, as well as some sample widgets, and can be used for reference. As it contains several independent examples, it is not built comprehensively, and we recommend against using it as a boilerplate. We continuously add new features to this repository as we create new Training guide materials.
8+
The [finished branch](https://github.com/Kentico/xperience-by-kentico-training-guides/tree/finished) contains the cumulative results of the training guides, as well as some sample widgets, and can be used for reference. As it contains several independent examples, it is not built comprehensively, and we recommend against using it as a boilerplate. We continuously add new features to this repository as we create new training guide materials.
99

10-
The goal of the [Training Guides](https://docs.kentico.com/guides/development) is to teach recommended development practices with Xperience by Kentico.
10+
The goal of the [training guides](https://docs.kentico.com/guides/development) is to teach recommended development practices with Xperience by Kentico.
1111
However, keep in mind that the code in this repository is intended to be examined in the context of individual guides -- some aspects are simplified to keep attention on the main topic of the corresponding lesson.
1212

1313
## Installation requirements
@@ -42,7 +42,7 @@ However, keep in mind that the code in this repository is intended to be examine
4242
4343
## Contributing
4444
45-
This repository is related to Training Guides for developers and has an educational purpose. For this reason, please do not submit ideas for new functionality. However, please do let us know if you encounter a bug that needs to be fixed, either by submitting an issue or contributing a fix directly.
45+
This repository is related to Training guides for developers and has an educational purpose. For this reason, please do not submit ideas for new functionality. However, please do let us know if you encounter a bug that needs to be fixed, either by submitting an issue or contributing a fix directly.
4646
4747
To see the guidelines for Contributing to Kentico open source software, please see [Kentico's `CONTRIBUTING.md`](https://github.com/Kentico/.github/blob/main/CONTRIBUTING.md) for more information and follow the [Kentico's `CODE_OF_CONDUCT`](https://github.com/Kentico/.github/blob/main/CODE_OF_CONDUCT.md).
4848
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
namespace TrainingGuides.Web.Features.Shared.Logging;
2+
3+
/// <summary>
4+
/// Contains event IDs for logging.
5+
/// </summary>
6+
internal static class EventIds
7+
{
8+
public static readonly EventId RetrieveUrl = new(1001, nameof(RetrieveUrl));
9+
public static readonly EventId MemberRegistration = new(1002, nameof(MemberRegistration));
10+
public static readonly EventId MemberSignIn = new(1003, nameof(MemberSignIn));
11+
}

src/TrainingGuides.Web/Features/Shared/Services/TrainingGuidesWebPageUrlRetriever.cs

Lines changed: 11 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,19 @@
11
using CMS;
22
using CMS.Core;
3+
using TrainingGuides.Web.Features.Shared.Logging;
34

45
[assembly: RegisterImplementation(typeof(IWebPageUrlRetriever), typeof(TrainingGuidesWebPageUrlRetriever))]
56
public class TrainingGuidesWebPageUrlRetriever : IWebPageUrlRetriever
67
{
78
private WebPageUrl EmptyUrl => new(string.Empty, string.Empty);
89
private readonly IWebPageUrlRetriever webPageUrlRetriever;
9-
private readonly IEventLogService eventLogService;
10+
private readonly ILogger<TrainingGuidesWebPageUrlRetriever> logger;
1011

1112
public TrainingGuidesWebPageUrlRetriever(IWebPageUrlRetriever webPageUrlRetriever,
12-
IEventLogService eventLogService)
13+
ILogger<TrainingGuidesWebPageUrlRetriever> logger)
1314
{
1415
this.webPageUrlRetriever = webPageUrlRetriever;
15-
this.eventLogService = eventLogService;
16+
this.logger = logger;
1617
}
1718

1819
/// <summary>
@@ -42,8 +43,7 @@ public async Task<WebPageUrl> Retrieve(IWebPageFieldsSource webPageFieldsSource,
4243
}
4344
catch (InvalidOperationException ex)
4445
{
45-
string message = $"{ex.Message}\r\nweb page guid: {webPageFieldsSource?.SystemFields.WebPageItemGUID},\r\nweb page id: {webPageFieldsSource?.SystemFields.WebPageItemID},\r\ntree path: {webPageFieldsSource?.SystemFields.WebPageItemTreePath}";
46-
eventLogService.LogError(ex.Source, "Retrieve URL", message);
46+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred while retrieving URL for web page with GUID {WebPageItemGuid} and ID {WebPageItemId} at path {TreePath}.", webPageFieldsSource?.SystemFields.WebPageItemGUID, webPageFieldsSource?.SystemFields.WebPageItemID, webPageFieldsSource?.SystemFields.WebPageItemTreePath);
4747
return EmptyUrl;
4848
}
4949
}
@@ -78,8 +78,7 @@ public async Task<WebPageUrl> Retrieve(IWebPageFieldsSource webPageFieldsSource,
7878
}
7979
catch (InvalidOperationException ex)
8080
{
81-
string message = $"{ex.Message}\r\nweb page guid: {webPageFieldsSource?.SystemFields.WebPageItemGUID},\r\nweb page id: {webPageFieldsSource?.SystemFields.WebPageItemID},\r\ntree path: {webPageFieldsSource?.SystemFields.WebPageItemTreePath}\r\nlanguage: {languageName}";
82-
eventLogService.LogError(ex.Source, "Retrieve URL", message);
81+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred while retrieving URL for web page with GUID {WebPageItemGuid} and ID {WebPageItemId} at path {TreePath} in language {LanguageName}.", webPageFieldsSource?.SystemFields.WebPageItemGUID, webPageFieldsSource?.SystemFields.WebPageItemID, webPageFieldsSource?.SystemFields.WebPageItemTreePath, languageName);
8382
return EmptyUrl;
8483
}
8584
}
@@ -113,8 +112,7 @@ public async Task<WebPageUrl> Retrieve(string webPageUrlPath, string webPageTree
113112
}
114113
catch (InvalidOperationException ex)
115114
{
116-
string message = $"{ex.Message}\r\ntree path: {webPageTreePath},\r\nweb page URL path: {webPageUrlPath},\r\nwebsite channel id: {websiteChannelId}\r\nlanguage: {languageName}";
117-
eventLogService.LogError(ex.Source, "Retrieve URL", message);
115+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred retrieving URL for web page with URL path {WebPageUrlPath} and tree path {WebPageTreePath} in website channel with ID {WebsiteChannelId} in language {languageName}.", webPageUrlPath, webPageTreePath, websiteChannelId, languageName);
118116
return EmptyUrl;
119117
}
120118
}
@@ -139,8 +137,7 @@ public async Task<WebPageUrl> Retrieve(int webPageItemId, string languageName, b
139137
}
140138
catch (InvalidOperationException ex)
141139
{
142-
string message = $"{ex.Message}\r\nweb page id: {webPageItemId},\r\nlanguage: {languageName}\r\nfor preview: {forPreview}";
143-
eventLogService.LogError(ex.Source, "Retrieve URL", message);
140+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred retrieving URL for web page with ID {WebPageItemId} in language {LanguageName} (for preview: {ForPreview}).", webPageItemId, languageName, forPreview);
144141
return EmptyUrl;
145142
}
146143
}
@@ -165,8 +162,7 @@ public async Task<WebPageUrl> Retrieve(Guid webPageItemGuid, string languageName
165162
}
166163
catch (InvalidOperationException ex)
167164
{
168-
string message = $"{ex.Message}\r\nweb page guid: {webPageItemGuid},\r\nlanguage: {languageName}\r\nfor preview: {forPreview}";
169-
eventLogService.LogError(ex.Source, "Retrieve URL", message);
165+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred retrieving URL for web page with GUID {WebPageItemGuid} in language {LanguageName} (for preview: {ForPreview}).", webPageItemGuid, languageName, forPreview);
170166
return EmptyUrl;
171167
}
172168
}
@@ -192,8 +188,7 @@ public async Task<IDictionary<Guid, WebPageUrl>> Retrieve(IReadOnlyCollection<Gu
192188
}
193189
catch (InvalidOperationException ex)
194190
{
195-
string message = $"{ex.Message}\r\nweb page guids: {string.Join(", ", webPageItemGuids)},\r\nwebsite channel name: {websiteChannelName},\r\nlanguage: {languageName}\r\nfor preview: {forPreview}";
196-
eventLogService.LogError(ex.Source, "Retrieve URLs", message);
191+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred retrieving URLs for web pages with GUIDs {WebPageItemGuids} in website channel {WebsiteChannelName} in language {LanguageName} (for preview: {ForPreview}).", string.Join(", ", webPageItemGuids), websiteChannelName, languageName, forPreview);
197192
return webPageItemGuids.ToDictionary(guid => guid, _ => EmptyUrl);
198193
}
199194
}
@@ -220,8 +215,7 @@ public async Task<WebPageUrl> Retrieve(string webPageTreePath, string websiteCha
220215
}
221216
catch (InvalidOperationException ex)
222217
{
223-
string message = $"{ex.Message}\r\ntree path: {webPageTreePath},\r\nwebsite channel name: {websiteChannelName},\r\nlanguage: {languageName}\r\nfor preview: {forPreview}";
224-
eventLogService.LogError(ex.Source, "Retrieve URL", message);
218+
logger.LogError(EventIds.RetrieveUrl, ex, "An error occurred retrieving URL for web page with tree path {WebPageTreePath} in website channel {WebsiteChannelName} in language {LanguageName} (for preview: {ForPreview}).", webPageTreePath, websiteChannelName, languageName, forPreview);
225219
return EmptyUrl;
226220
}
227221
}

src/TrainingGuides.Web/appsettings.json

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,12 @@
55
"Microsoft": "Warning",
66
"Microsoft.Hosting.Lifetime": "Information"
77
},
8-
"KenticoEventLog": {
8+
"XperienceEventLog": {
99
"LogLevel": {
10-
"Default": "Error",
10+
"Default": "Warning",
11+
"Kentico": "Information",
12+
"CMS": "Information",
13+
"TrainingGuides": "Debug",
1114
"Microsoft.AspNetCore.Server.Kestrel": "None"
1215
}
1316
}

0 commit comments

Comments
 (0)