Skip to content

Commit ee1c7e7

Browse files
authored
Merge pull request #6948 from umbraco/logviewer
Updated logviewer article for versions 14 and 15
2 parents 56af924 + 7a0d37d commit ee1c7e7

File tree

2 files changed

+74
-76
lines changed

2 files changed

+74
-76
lines changed

14/umbraco-cms/fundamentals/backoffice/logviewer.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ description: Information on using the Umbraco log viewer
44

55
# Log Viewer
66

7-
Umbraco ships with a built-in Log Viewer feature. This allows you to filter and view log entries and perform much more complex search queries. This helps you find the log entries that you are interested in. You can find the Log viewer in the Settings section.
7+
Umbraco ships with a built-in Log Viewer feature. This allows you to filter, view log entries, perform complex search queries, and analyze logs for debugging. You can find the Log viewer in the **Settings** section of the Umbraco backoffice.
88

99
{% embed url="https://youtu.be/PDqIRVygAQ4?t=102" %}
1010
Learn how to use the Log Viewer to read and understand logs for your Umbraco CMS website.
1111
{% endembed %}
1212

1313
## Benefits
1414

15-
Have you ever wanted to find all log entries which contain the same request ID? Or find all items in the log where a property called duration is greater than 1000ms?
15+
Ever needed to find all log entries containing the same request ID? Or locate all logs where a property called `Duration` exceeds 1000ms?
1616

17-
With the power of structured logging and a query language, we are able to search and find log items for specific scenarios. When debugging the site you should now have more power to see and find patterns in your log files and get rid of those errors.
17+
With structured logging and a query language, you can efficiently search and identify log items for specific scenarios. This helps in debugging and finding patterns in your logs, making it easier to resolve issues.
1818

19-
## Example queries
19+
## Example Queries
2020

21-
Here are a handful of example queries to get you started, however, the saved searches contain some further examples. For more details on the syntax head over to the https://github.com/serilog/serilog-filters-expressions project.
21+
Here are some example queries to help you get started. For more details on the syntax, see the https://github.com/serilog/serilog-filters-expressions project.
2222

23-
**Find all logs that are from the namespace 'Umbraco.Core'**\
24-
`StartsWith(SourceContext, 'Umbraco.Core')`\\
23+
**Find all logs that are from the namespace 'Umbraco.Core'**
24+
`StartsWith(SourceContext, 'Umbraco.Core')`
2525

26-
**Find all logs that have the property 'Duration' and the duration is greater than 1000ms**\
27-
`Has(Duration) and Duration > 1000`\\
26+
**Find all logs that have the property 'Duration' and the duration is greater than 1000ms**
27+
`Has(Duration) and Duration > 1000`
2828

29-
**Find all logs where the message has localhost in it with SQL like**\
30-
`@Message like '%localhost%'`\\
29+
**Find all logs where the message has localhost in it with SQL like**
30+
`@Message like '%localhost%'`
3131

3232
## Saved Searches
3333

34-
Sometimes you want to use a custom query more often. It is possible to save a query and use the dropdown to re-use your saved search. To add a new saved search, use the search box to type your query and click the star icon. In doing so you can give it a friendly name. The saved queries are saved in the database in the table `umbracoLogViewerQuery`.
34+
If you frequently use a custom query, you can save it for quick access. Type your query in the search box and click the heart icon to save it with a friendly name. Saved queries are stored in the `umbracoLogViewerQuery` table in the database.
3535

36-
## Implementing your own Log Viewer
36+
## Implementing Your Own Log Viewer
3737

38-
With the flexibility of Umbraco, we give you the power to implement your own `ILogViewer`. This makes it possible to fetch logs and the saved searches from a different location such as Azure table storage.
38+
Umbraco allows you to implement a customn `ILogViewer` to fetch logs from alternative sources, such as **Azure Table Storage**.
3939

40-
### Create your own implementation
40+
### Creating a Custom Log Viewer
4141

42-
To do this we can implement a base class `SerilogLogViewerSourceBase` from `Umbraco.Cms.Core.Logging.Viewer` like so.
42+
To fetch logs from Azure Table Storage, implement the `SerilogLogViewerSourceBase` class from `Umbraco.Cms.Core.Logging.Viewer`.
4343

4444
{% hint style="info" %}
45-
This uses the `Azure.Data.Tables` NuGet package.
45+
This implementation requires the `Azure.Data.Tables` NuGet package.
4646
{% endhint %}
4747

4848
```csharp
@@ -70,6 +70,7 @@ public class AzureTableLogViewer : SerilogLogViewerSourceBase
7070

7171
protected override IReadOnlyList<LogEvent> GetLogs(LogTimePeriod logTimePeriod, ILogFilter filter, int skip, int take)
7272
{
73+
//Replace ACCOUNT_NAME and KEY with your actual Azure Storage Account details. The "Logs" parameter refers to the table name where logs will be stored and retrieved from.
7374
var client =
7475
new TableClient(
7576
"DefaultEndpointsProtocol=https;AccountName=ACCOUNT_NAME;AccountKey=KEY;EndpointSuffix=core.windows.net",
@@ -80,32 +81,32 @@ public class AzureTableLogViewer : SerilogLogViewerSourceBase
8081
var requiredEntities = skip + take;
8182
IEnumerable<AzureTableLogEntity> results = client.Query<AzureTableLogEntity>().Take(requiredEntities);
8283

83-
return results
84-
.Skip(skip)
85-
.Take(take)
86-
.Select(x => LogEventReader.ReadFromString(x.Data))
84+
return results
85+
.Skip(skip)
86+
.Take(take)
87+
.Select(x => LogEventReader.ReadFromString(x.Data))
8788
// Filter by timestamp to avoid retrieving all logs from the table, preventing memory and performance issues
88-
.Where(evt => evt.Timestamp >= logTimePeriod.StartTime.Date &&
89-
evt.Timestamp <= logTimePeriod.EndTime.Date.AddDays(1).AddSeconds(-1))
90-
.Where(filter.TakeLogEvent)
91-
.ToList();
89+
.Where(evt => evt.Timestamp >= logTimePeriod.StartTime.Date &&
90+
evt.Timestamp <= logTimePeriod.EndTime.Date.AddDays(1).AddSeconds(-1))
91+
.Where(filter.TakeLogEvent)
92+
.ToList();
9293
}
9394

9495
public override IReadOnlyList<SavedLogSearch>? GetSavedSearches()
9596
{
96-
// Optional: If you want to store saved searches in the Azure Table Storage, implement here a method to fetch from the Azure Table.
97+
//This method is optional. If you store saved searches in Azure Table Storage, implement fetching logic here.
9798
return base.GetSavedSearches();
9899
}
99100

100101
public override IReadOnlyList<SavedLogSearch>? AddSavedSearch(string? name, string? query)
101102
{
102-
//Optional: If you want to store saved searches in the Azure Table Storage, implement here a method to add to the Azure Table.
103+
//This method is optional. If you store saved searches in Azure Table Storage, implement adding logic here.
103104
return base.AddSavedSearch(name, query);
104105
}
105106

106107
public override IReadOnlyList<SavedLogSearch>? DeleteSavedSearch(string? name, string? query)
107108
{
108-
//Optional: If you want to store saved searches in the Azure Table Storage, implement here a method to remove from the Azure Table.
109+
//This method is optional. If you store saved searches in Azure Table Storage, implement deleting logic here.
109110
return base.DeleteSavedSearch(name, query);
110111
}
111112
}
@@ -118,7 +119,7 @@ public class AzureTableLogEntity : LogEventEntity, ITableEntity
118119
}
119120
```
120121

121-
Keep in mind that we have to implement our own version of a `LogEventEntity`. This is because the `TableClient` needs whatever it is fetching to implement the `ITableEntity` interface.
122+
Azure Table Storage requires entities to implement the `ITableEntity` interface. Since Umbraco’s default log entity does not implement this, a custom entity (`AzureTableLogEntity`) must be created to ensure logs are correctly fetched and stored.
122123

123124
### Register implementation
124125

@@ -136,14 +137,14 @@ public class LogViewerSavedSearches : IComposer
136137
}
137138
```
138139

139-
### Configure Umbraco to log into Azure Table Storage
140+
### Configuring Logging to Azure Table Storage
140141

141-
Now with the above two classes, we have the plumbing in place to view logs from an Azure Table. However, we are not persisting our logs into the Azure table storage account. So we need to configure the Serilog logging pipeline to store our logs in Azure table storage.
142+
With the above two classes, the setup is in place to view logs from an Azure Table. However, logs are not yet persisted into the Azure Table Storage account. To enable persistence, configure the Serilog logging pipeline to store logs in Azure Table Storage.
142143

143-
* Install Serilog.Sinks.AzureTableStorage from Nuget
144-
* Add a new sink to the appsettings with credentials (so logs persist to Azure)
144+
* Install `Serilog.Sinks.AzureTableStorage` from NuGet.
145+
* Add a new sink to `appsettings.json` with credentials to persist logs to Azure.
145146

146-
The following sink needs to be added to the array [`Serilog:WriteTo`](https://github.com/serilog/serilog-sinks-azuretablestorage#json-configuration).
147+
The following sink needs to be added to the [`Serilog:WriteTo`](https://github.com/serilog/serilog-sinks-azuretablestorage#json-configuration) array.
147148

148149
```json
149150
{
@@ -155,10 +156,8 @@ The following sink needs to be added to the array [`Serilog:WriteTo`](https://gi
155156
}
156157
```
157158

158-
For more in-depth information about logging and how to configure it, please read the [logging documentation](../code/debugging/logging.md).
159+
For more in-depth information about logging and how to configure it, see the [Logging](../code/debugging/logging.md) article.
159160

160161
### Compact Log Viewer - Desktop App
161162

162-
This is a desktop tool for viewing & querying JSON log files from disk in the same way as the built-in logviewer dashboard of Umbraco.
163-
164-
[<img src="../../../../10/umbraco-cms/fundamentals/backoffice/images/English_get.png" alt="English badge" data-size="line">](https://www.microsoft.com/store/apps/9N8RV8LKTXRJ?cid=storebadge\&ocid=badge)
163+
[Compact Log Viewer](https://www.microsoft.com/store/apps/9N8RV8LKTXRJ?cid=storebadge\&ocid=badge). A desktop tool is available for viewing and querying JSON log files in the same way as the built-in Log Viewer in Umbraco.

15/umbraco-cms/fundamentals/backoffice/logviewer.md

Lines changed: 37 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -4,45 +4,45 @@ description: Information on using the Umbraco log viewer
44

55
# Log Viewer
66

7-
Umbraco ships with a built-in Log Viewer feature. This allows you to filter and view log entries and perform much more complex search queries. This helps you find the log entries that you are interested in. You can find the Log viewer in the Settings section.
7+
Umbraco ships with a built-in Log Viewer feature. This allows you to filter, view log entries, perform complex search queries, and analyze logs for debugging. You can find the Log viewer in the **Settings** section of the Umbraco backoffice.
88

99
{% embed url="https://youtu.be/PDqIRVygAQ4?t=102" %}
1010
Learn how to use the Log Viewer to read and understand logs for your Umbraco CMS website.
1111
{% endembed %}
1212

1313
## Benefits
1414

15-
Have you ever wanted to find all log entries which contain the same request ID? Or find all items in the log where a property called duration is greater than 1000ms?
15+
Ever needed to find all log entries containing the same request ID? Or locate all logs where a property called `Duration` exceeds 1000ms?
1616

17-
With the power of structured logging and a query language, we are able to search and find log items for specific scenarios. When debugging the site you should now have more power to see and find patterns in your log files and get rid of those errors.
17+
With structured logging and a query language, you can efficiently search and identify log items for specific scenarios. This helps in debugging and finding patterns in your logs, making it easier to resolve issues.
1818

19-
## Example queries
19+
## Example Queries
2020

21-
Here are a handful of example queries to get you started, however, the saved searches contain some further examples. For more details on the syntax head over to the https://github.com/serilog/serilog-filters-expressions project.
21+
Here are some example queries to help you get started. For more details on the syntax, see the https://github.com/serilog/serilog-filters-expressions project.
2222

23-
**Find all logs that are from the namespace 'Umbraco.Core'**\
24-
`StartsWith(SourceContext, 'Umbraco.Core')`\\
23+
**Find all logs that are from the namespace 'Umbraco.Core'**
24+
`StartsWith(SourceContext, 'Umbraco.Core')`
2525

26-
**Find all logs that have the property 'Duration' and the duration is greater than 1000ms**\
27-
`Has(Duration) and Duration > 1000`\\
26+
**Find all logs that have the property 'Duration' and the duration is greater than 1000ms**
27+
`Has(Duration) and Duration > 1000`
2828

29-
**Find all logs where the message has localhost in it with SQL like**\
30-
`@Message like '%localhost%'`\\
29+
**Find all logs where the message has localhost in it with SQL like**
30+
`@Message like '%localhost%'`
3131

3232
## Saved Searches
3333

34-
Sometimes you want to use a custom query more often. It is possible to save a query and use the dropdown to re-use your saved search. To add a new saved search, use the search box to type your query and click the star icon. In doing so you can give it a friendly name. The saved queries are saved in the database in the table `umbracoLogViewerQuery`.
34+
If you frequently use a custom query, you can save it for quick access. Type your query in the search box and click the heart icon to save it with a friendly name. Saved queries are stored in the `umbracoLogViewerQuery` table in the database.
3535

36-
## Implementing your own Log Viewer
36+
## Implementing Your Own Log Viewer
3737

38-
With the flexibility of Umbraco, we give you the power to implement your own `ILogViewer`. This makes it possible to fetch logs and the saved searches from a different location such as Azure table storage.
38+
Umbraco allows you to implement a customn `ILogViewer` to fetch logs from alternative sources, such as **Azure Table Storage**.
3939

40-
### Create your own implementation
40+
### Creating a Custom Log Viewer
4141

42-
To do this we can implement a base class `SerilogLogViewerSourceBase` from `Umbraco.Cms.Core.Logging.Viewer` like so.
42+
To fetch logs from Azure Table Storage, implement the `SerilogLogViewerSourceBase` class from `Umbraco.Cms.Core.Logging.Viewer`.
4343

4444
{% hint style="info" %}
45-
This uses the `Azure.Data.Tables` NuGet package.
45+
This implementation requires the `Azure.Data.Tables` NuGet package.
4646
{% endhint %}
4747

4848
```csharp
@@ -70,6 +70,7 @@ public class AzureTableLogViewer : SerilogLogViewerSourceBase
7070

7171
protected override IReadOnlyList<LogEvent> GetLogs(LogTimePeriod logTimePeriod, ILogFilter filter, int skip, int take)
7272
{
73+
//Replace ACCOUNT_NAME and KEY with your actual Azure Storage Account details. The "Logs" parameter refers to the table name where logs will be stored and retrieved from.
7374
var client =
7475
new TableClient(
7576
"DefaultEndpointsProtocol=https;AccountName=ACCOUNT_NAME;AccountKey=KEY;EndpointSuffix=core.windows.net",
@@ -80,32 +81,32 @@ public class AzureTableLogViewer : SerilogLogViewerSourceBase
8081
var requiredEntities = skip + take;
8182
IEnumerable<AzureTableLogEntity> results = client.Query<AzureTableLogEntity>().Take(requiredEntities);
8283

83-
return results
84-
.Skip(skip)
85-
.Take(take)
86-
.Select(x => LogEventReader.ReadFromString(x.Data))
84+
return results
85+
.Skip(skip)
86+
.Take(take)
87+
.Select(x => LogEventReader.ReadFromString(x.Data))
8788
// Filter by timestamp to avoid retrieving all logs from the table, preventing memory and performance issues
88-
.Where(evt => evt.Timestamp >= logTimePeriod.StartTime.Date &&
89-
evt.Timestamp <= logTimePeriod.EndTime.Date.AddDays(1).AddSeconds(-1))
90-
.Where(filter.TakeLogEvent)
91-
.ToList();
89+
.Where(evt => evt.Timestamp >= logTimePeriod.StartTime.Date &&
90+
evt.Timestamp <= logTimePeriod.EndTime.Date.AddDays(1).AddSeconds(-1))
91+
.Where(filter.TakeLogEvent)
92+
.ToList();
9293
}
9394

9495
public override IReadOnlyList<SavedLogSearch>? GetSavedSearches()
9596
{
96-
// Optional: If you want to store saved searches in the Azure Table Storage, implement here a method to fetch from the Azure Table.
97+
//This method is optional. If you store saved searches in Azure Table Storage, implement fetching logic here.
9798
return base.GetSavedSearches();
9899
}
99100

100101
public override IReadOnlyList<SavedLogSearch>? AddSavedSearch(string? name, string? query)
101102
{
102-
//Optional: If you want to store saved searches in the Azure Table Storage, implement here a method to add to the Azure Table.
103+
//This method is optional. If you store saved searches in Azure Table Storage, implement adding logic here.
103104
return base.AddSavedSearch(name, query);
104105
}
105106

106107
public override IReadOnlyList<SavedLogSearch>? DeleteSavedSearch(string? name, string? query)
107108
{
108-
//Optional: If you want to store saved searches in the Azure Table Storage, implement here a method to remove from the Azure Table.
109+
//This method is optional. If you store saved searches in Azure Table Storage, implement deleting logic here.
109110
return base.DeleteSavedSearch(name, query);
110111
}
111112
}
@@ -118,7 +119,7 @@ public class AzureTableLogEntity : LogEventEntity, ITableEntity
118119
}
119120
```
120121

121-
Keep in mind that we have to implement our own version of a `LogEventEntity`. This is because the `TableClient` needs whatever it is fetching to implement the `ITableEntity` interface.
122+
Azure Table Storage requires entities to implement the `ITableEntity` interface. Since Umbraco’s default log entity does not implement this, a custom entity (`AzureTableLogEntity`) must be created to ensure logs are correctly fetched and stored.
122123

123124
### Register implementation
124125

@@ -136,14 +137,14 @@ public class LogViewerSavedSearches : IComposer
136137
}
137138
```
138139

139-
### Configure Umbraco to log into Azure Table Storage
140+
### Configuring Logging to Azure Table Storage
140141

141-
Now with the above two classes, we have the plumbing in place to view logs from an Azure Table. However, we are not persisting our logs into the Azure table storage account. So we need to configure the Serilog logging pipeline to store our logs in Azure table storage.
142+
With the above two classes, the setup is in place to view logs from an Azure Table. However, logs are not yet persisted into the Azure Table Storage account. To enable persistence, configure the Serilog logging pipeline to store logs in Azure Table Storage.
142143

143-
* Install Serilog.Sinks.AzureTableStorage from Nuget
144-
* Add a new sink to the appsettings with credentials (so logs persist to Azure)
144+
* Install `Serilog.Sinks.AzureTableStorage` from NuGet.
145+
* Add a new sink to `appsettings.json` with credentials to persist logs to Azure.
145146

146-
The following sink needs to be added to the array [`Serilog:WriteTo`](https://github.com/serilog/serilog-sinks-azuretablestorage#json-configuration).
147+
The following sink needs to be added to the [`Serilog:WriteTo`](https://github.com/serilog/serilog-sinks-azuretablestorage#json-configuration) array.
147148

148149
```json
149150
{
@@ -155,10 +156,8 @@ The following sink needs to be added to the array [`Serilog:WriteTo`](https://gi
155156
}
156157
```
157158

158-
For more in-depth information about logging and how to configure it, please read the [logging documentation](../code/debugging/logging.md).
159+
For more in-depth information about logging and how to configure it, see the [Logging](../code/debugging/logging.md) article.
159160

160161
### Compact Log Viewer - Desktop App
161162

162-
This is a desktop tool for viewing & querying JSON log files from disk in the same way as the built-in logviewer dashboard of Umbraco.
163-
164-
[<img src="../../../../10/umbraco-cms/fundamentals/backoffice/images/English_get.png" alt="English badge" data-size="line">](https://www.microsoft.com/store/apps/9N8RV8LKTXRJ?cid=storebadge\&ocid=badge)
163+
[Compact Log Viewer](https://www.microsoft.com/store/apps/9N8RV8LKTXRJ?cid=storebadge\&ocid=badge). A desktop tool is available for viewing and querying JSON log files in the same way as the built-in Log Viewer in Umbraco.

0 commit comments

Comments
 (0)