Skip to content

Commit f8acd39

Browse files
authored
Merge pull request #6513 from erikjanwestendorp/update-logging
Porting old Umbraco API Controller [Debugging > Logging]
2 parents a873cfe + f8a4ffb commit f8acd39

File tree

4 files changed

+30
-32
lines changed
  • 10/umbraco-cms/fundamentals/code/debugging
  • 13/umbraco-cms/fundamentals/code/debugging
  • 14/umbraco-cms/fundamentals/code/debugging
  • 15/umbraco-cms/fundamentals/code/debugging

4 files changed

+30
-32
lines changed

10/umbraco-cms/fundamentals/code/debugging/logging.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ keywords: logging serilog messagetemplates logs v9 version9
66

77
In Umbraco we use the underlying logging framework of [Serilog](https://serilog.net/).
88

9-
Out of the box we write a JSON log file that contains a more rich logfile, that allows tools to perform searches & correlation on log patterns a lot easier.
9+
Out of the box, we write a JSON log file that contains a more detailed logfile. This allows tools to perform searches and correlations on log patterns more efficiently.
1010

1111
The default location of this file is written to `umbraco/Logs` and contains the Machine name, along with the date too:
1212

@@ -20,7 +20,7 @@ Serilog is a logging framework that allows us to do structured logging or write
2020
2021-08-10 09:33:23,677 [P25776/D1/T22] INFO Umbraco.Cms.Core.Services.Implement.ContentService - Document Home (id=1062) has been published.
2121
```
2222

23-
Here is an example of the same log message represented as JSON, you can see here we have much more information that would allow us to search & filter logs based on these properties with an appropriate logging system.
23+
Here is an example of the same log message represented as JSON. More information is available and allows you to search and filter logs based on these properties with an appropriate logging system.
2424

2525
```json
2626
{
@@ -46,13 +46,13 @@ Here is an example of the same log message represented as JSON, you can see here
4646
}
4747
```
4848

49-
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website or alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
49+
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website. Alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
5050

5151
## Writing to the log
5252

53-
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed, so you can get further insights and details about your implementation.
53+
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed. This allows you to gain further insights and details about your implementation.
5454

55-
Here is an example of using the logger to write an Information message to the log which will contain one property of **Name** which will output the name variable that is passed into the method
55+
Here is an example of using the logger to write an Information message to the log. It will contain one property, **Name**, which will output the name variable that is passed into the method.
5656

5757
```csharp
5858
using Microsoft.AspNetCore.Mvc;

13/umbraco-cms/fundamentals/code/debugging/logging.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In Umbraco we use the underlying logging framework of [Serilog](https://serilog.net/).
44

5-
Out of the box we write a JSON log file that contains a more rich logfile, that allows tools to perform searches & correlation on log patterns a lot easier.
5+
Out of the box, we write a JSON log file that contains a more detailed logfile. This allows tools to perform searches and correlations on log patterns more efficiently.
66

77
The default location of this file is written to `umbraco/Logs` and contains the Machine name, along with the date too:
88

@@ -22,7 +22,7 @@ Serilog is a logging framework that allows us to do structured logging or write
2222
2021-08-10 09:33:23,677 [P25776/D1/T22] INFO Umbraco.Cms.Core.Services.Implement.ContentService - Document Home (id=1062) has been published.
2323
```
2424

25-
Here is an example of the same log message represented as JSON, you can see here we have much more information that would allow us to search & filter logs based on these properties with an appropriate logging system.
25+
Here is an example of the same log message represented as JSON. More information is available and allows you to search and filter logs based on these properties with an appropriate logging system.
2626

2727
```json
2828
{
@@ -48,13 +48,13 @@ Here is an example of the same log message represented as JSON, you can see here
4848
}
4949
```
5050

51-
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website or alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
51+
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website. Alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
5252

5353
## Writing to the log
5454

55-
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed, so you can get further insights and details about your implementation.
55+
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed. This allows you to gain further insights and details about your implementation.
5656

57-
Here is an example of using the logger to write an Information message to the log which will contain one property of **Name** which will output the name variable that is passed into the method
57+
Here is an example of using the logger to write an Information message to the log. It will contain one property, **Name**, which will output the name variable that is passed into the method.
5858

5959
```csharp
6060
using Microsoft.AspNetCore.Mvc;

14/umbraco-cms/fundamentals/code/debugging/logging.md

Lines changed: 11 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,16 @@
22

33
In Umbraco we use the underlying logging framework of [Serilog](https://serilog.net/).
44

5-
Out of the box we write a JSON log file that contains a more rich logfile, that allows tools to perform searches & correlation on log patterns a lot easier.
5+
Out of the box, we write a JSON log file that contains a more detailed logfile. This allows tools to perform searches and correlations on log patterns more efficiently.
66

77
The default location of this file is written to `umbraco/Logs` and contains the Machine name, along with the date too:
88

99
* `umbraco/Logs/UmbracoTraceLog.DELLBOOK.20210809.json`
1010

11-
## Video overview
11+
## Video Overview
1212

1313
{% embed url="<https://youtu.be/PDqIRVygAQ4>" %}
14-
Watch this video to get an overview of how to view and manage logs and logfiles for your Umbraco CMS website.
14+
Watch this video to get an overview of how to view and manage logs and log files for your Umbraco CMS website.
1515
{% endembed %}
1616

1717
## Structured logging
@@ -22,7 +22,7 @@ Serilog is a logging framework that allows us to do structured logging or write
2222
2021-08-10 09:33:23,677 [P25776/D1/T22] INFO Umbraco.Cms.Core.Services.Implement.ContentService - Document Home (id=1062) has been published.
2323
```
2424

25-
Here is an example of the same log message represented as JSON, you can see here we have much more information that would allow us to search & filter logs based on these properties with an appropriate logging system.
25+
Here is an example of the same log message represented as JSON. More information is available and allows you to search and filter logs based on these properties with an appropriate logging system.
2626

2727
```json
2828
{
@@ -48,26 +48,23 @@ Here is an example of the same log message represented as JSON, you can see here
4848
}
4949
```
5050

51-
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website or alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
51+
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website. Alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
5252

5353
## Writing to the log
5454

55-
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed, so you can get further insights and details about your implementation.
55+
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed. This allows you to gain further insights and details about your implementation.
5656

57-
Here is an example of using the logger to write an Information message to the log which will contain one property of **Name** which will output the name variable that is passed into the method
58-
59-
{% hint style="warning" %}
60-
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
61-
{% endhint %}
57+
Here is an example of using the logger to write an Information message to the log. It will contain one property, **Name**, which will output the name variable that is passed into the method.
6258

6359
```csharp
6460
using Microsoft.AspNetCore.Mvc;
6561
using Microsoft.Extensions.Logging;
66-
using Umbraco.Cms.Web.Common.Controllers;
6762

6863
namespace Umbraco.Cms.Web.UI.NetCore;
6964

70-
public class MyApiController : UmbracoApiController
65+
[ApiController]
66+
[Route("/umbraco/api/myapi")]
67+
public class MyApiController : Controller
7168
{
7269
private readonly ILogger<MyApiController> _logger;
7370

@@ -77,7 +74,7 @@ public class MyApiController : UmbracoApiController
7774
}
7875

7976
/// /umbraco/api/MyApi/SayHello?name=John
80-
[HttpGet]
77+
[HttpGet("sayhello")]
8178
public string SayHello(string name)
8279
{
8380
_logger.LogInformation("We are saying hello to {Name}", name);

15/umbraco-cms/fundamentals/code/debugging/logging.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
In Umbraco we use the underlying logging framework of [Serilog](https://serilog.net/).
44

5-
Out of the box we write a JSON log file that contains a more rich logfile, that allows tools to perform searches & correlation on log patterns a lot easier.
5+
Out of the box, we write a JSON log file that contains a more detailed logfile. This allows tools to perform searches and correlations on log patterns more efficiently.
66

77
The default location of this file is written to `umbraco/Logs` and contains the Machine name, along with the date too:
88

@@ -22,7 +22,7 @@ Serilog is a logging framework that allows us to do structured logging or write
2222
2021-08-10 09:33:23,677 [P25776/D1/T22] INFO Umbraco.Cms.Core.Services.Implement.ContentService - Document Home (id=1062) has been published.
2323
```
2424

25-
Here is an example of the same log message represented as JSON, you can see here we have much more information that would allow us to search & filter logs based on these properties with an appropriate logging system.
25+
Here is an example of the same log message represented as JSON. More information is available and allows you to search and filter logs based on these properties with an appropriate logging system.
2626

2727
```json
2828
{
@@ -48,13 +48,13 @@ Here is an example of the same log message represented as JSON, you can see here
4848
}
4949
```
5050

51-
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website or alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
51+
To learn more about structured logging and message templates you can read more about it over on the [https://messagetemplates.org](https://messagetemplates.org) website. Alternatively watch this video from the Serilog creator - [https://www.youtube.com/watch?v=OhmNp8UPEEg](https://www.youtube.com/watch?v=OhmNp8UPEEg)
5252

5353
## Writing to the log
5454

55-
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed, so you can get further insights and details about your implementation.
55+
Umbraco writes log messages, but you are also able to use the Umbraco logger to write the log file as needed. This allows you to gain further insights and details about your implementation.
5656

57-
Here is an example of using the logger to write an Information message to the log which will contain one property of **Name** which will output the name variable that is passed into the method
57+
Here is an example of using the logger to write an Information message to the log. It will contain one property, **Name**, which will output the name variable that is passed into the method.
5858

5959
{% hint style="warning" %}
6060
The example below uses UmbracoApiController which is obsolete in Umbraco 14 and will be removed in Umbraco 15.
@@ -63,11 +63,12 @@ The example below uses UmbracoApiController which is obsolete in Umbraco 14 and
6363
```csharp
6464
using Microsoft.AspNetCore.Mvc;
6565
using Microsoft.Extensions.Logging;
66-
using Umbraco.Cms.Web.Common.Controllers;
6766

6867
namespace Umbraco.Cms.Web.UI.NetCore;
6968

70-
public class MyApiController : UmbracoApiController
69+
[ApiController]
70+
[Route("/umbraco/api/myapi")]
71+
public class MyApiController : Controller
7172
{
7273
private readonly ILogger<MyApiController> _logger;
7374

@@ -77,7 +78,7 @@ public class MyApiController : UmbracoApiController
7778
}
7879

7980
/// /umbraco/api/MyApi/SayHello?name=John
80-
[HttpGet]
81+
[HttpGet("sayhello")]
8182
public string SayHello(string name)
8283
{
8384
_logger.LogInformation("We are saying hello to {Name}", name);

0 commit comments

Comments
 (0)