Library

Video Player is loading.
 
Current Time 0:00
Duration 15:15
Loaded: 0%
 

x1.00


Back

Games & Quizzes

Training Mode - Typing
Fill the gaps to the Lyric - Best method
Training Mode - Picking
Pick the correct word to fill in the gap
Fill In The Blank
Find the missing words in a sentence Requires 5 vocabulary annotations
Vocabulary Match
Match the words to the definitions Requires 10 vocabulary annotations

You may need to watch a part of the video to unlock quizzes

Don't forget to Sign In to save your points

Challenge Accomplished

PERFECT HITS +NaN
HITS +NaN
LONGEST STREAK +NaN
TOTAL +
- //

We couldn't find definitions for the word you were looking for.
Or maybe the current language is not supported

  • 00:00

    Hi, this is Mike Rousos from the .NET Customer Success Team. I'm going to talk today briefly about logging in ASP.NET Core.
    Hi, this is Mike Rousos from the .NET Customer Success Team. I'm going to talk today briefly about logging in ASP.NET Core.

  • 00:08

    So, if you have an ASP.NET Core app and you want to log some diagnostics,
    So, if you have an ASP.NET Core app and you want to log some diagnostics,

  • 00:12

    you're typically going to be using the Microsoft.Extensions.Logging package. Let me hop over to NuGet and show that to you.
    you're typically going to be using the Microsoft.Extensions.Logging package. Let me hop over to NuGet and show that to you.

  • 00:22

    Microsoft.Extensions.Logging is what you're looking for.
    Microsoft.Extensions.Logging is what you're looking for.

  • 00:25

    You won't have to install this, typically, because it's already included in the package references for all of our ASP.NET Core
    You won't have to install this, typically, because it's already included in the package references for all of our ASP.NET Core

  • 00:32

    templates, but this is the package that you use and, like all, Microsoft.Extensions packages,
    templates, but this is the package that you use and, like all, Microsoft.Extensions packages,

  • 00:38

    there's nothing in here specific to ASP.NET Core. This just
    there's nothing in here specific to ASP.NET Core. This just

  • 00:42

    depends on .NET Standard 1.1, so you could just as easily
    depends on .NET Standard 1.1, so you could just as easily

  • 00:45

    use this logging framework in a .NET Core console app, .NET Framework app, UWP, just the same as you would in
    use this logging framework in a .NET Core console app, .NET Framework app, UWP, just the same as you would in

  • 00:52

    ASP.NET Core.
    ASP.NET Core.

  • 00:54

    But, coming back to how it works in ASP.NET Core,
    But, coming back to how it works in ASP.NET Core,

  • 00:58

    when you look at your ASP.NET Core app, you'll notice that in the templates our configure method in Startup.cs
    when you look at your ASP.NET Core app, you'll notice that in the templates our configure method in Startup.cs

  • 01:05

    will take an ILoggerFactory. This logger factory is what produces logger objects which we use to log events.
    will take an ILoggerFactory. This logger factory is what produces logger objects which we use to log events.

  • 01:13

    In the configure method, though, we need to set it up with all of the providers we want to use
    In the configure method, though, we need to set it up with all of the providers we want to use

  • 01:18

    for writing those logged messages to different endpoints. Now, one of the great things about the Microsoft.Extensions.Logging framework
    for writing those logged messages to different endpoints. Now, one of the great things about the Microsoft.Extensions.Logging framework

  • 01:26

    used in ASP.NET Core is its flexibility and its extensibility.
    used in ASP.NET Core is its flexibility and its extensibility.

  • 01:32

    By default, you'll have an .AddDebug which adds a debug provider so that we write to debug output.
    By default, you'll have an .AddDebug which adds a debug provider so that we write to debug output.

  • 01:37

    And you typically also have an .AddConsole
    And you typically also have an .AddConsole

  • 01:41

    as well in your
    as well in your

  • 01:45

    template that you start with and this will just write debug
    template that you start with and this will just write debug

  • 01:48

    diagnostic messages out to the console output, of course.
    diagnostic messages out to the console output, of course.

  • 01:51

    But when you look at these, these are extension methods AddConsole, AddDebug.
    But when you look at these, these are extension methods AddConsole, AddDebug.

  • 01:56

    And they're just extension methods that wrap ILoggerFactory.AddProvider
    And they're just extension methods that wrap ILoggerFactory.AddProvider

  • 02:02

    which adds an IloggerProvider.
    which adds an IloggerProvider.

  • 02:04

    So you could very easily go out and write your own ILoggerProvider for any endpoint
    So you could very easily go out and write your own ILoggerProvider for any endpoint

  • 02:09

    you want although you probably don't need to because someone else already has
    you want although you probably don't need to because someone else already has

  • 02:12

    most likely and I'll show you some of the many options here later in this video.
    most likely and I'll show you some of the many options here later in this video.

  • 02:16

    But in your configure method, you add the providers, the logging syncs that you're going to be using. Now you notice that
    But in your configure method, you add the providers, the logging syncs that you're going to be using. Now you notice that

  • 02:23

    typically, we'll say, you know, if it's not development, we'll do one set of things (which would not be this) and then if it
    typically, we'll say, you know, if it's not development, we'll do one set of things (which would not be this) and then if it

  • 02:31

    is a development environment, then maybe we'll hook up some more which I'll talk about in a minute.
    is a development environment, then maybe we'll hook up some more which I'll talk about in a minute.

  • 02:36

    But you want to do this sort of per-environment
    But you want to do this sort of per-environment

  • 02:40

    configuration of your logging providers because logging can have a performance hit.
    configuration of your logging providers because logging can have a performance hit.

  • 02:45

    Some logging providers like ETW log providers are fairly fast, especially if you're only logging high-priority
    Some logging providers like ETW log providers are fairly fast, especially if you're only logging high-priority

  • 02:52

    messages. But pretty much any console
    messages. But pretty much any console

  • 02:54

    log provider is going to slow things down.
    log provider is going to slow things down.

  • 02:57

    Some others that don't batch
    Some others that don't batch

  • 03:00

    can be slow. So you want to be cautious with how much logging you do in production. You want to kind of
    can be slow. So you want to be cautious with how much logging you do in production. You want to kind of

  • 03:06

    keep it to just the minimum batching
    keep it to just the minimum batching

  • 03:10

    providers which
    providers which

  • 03:12

    don't write out to the console.
    don't write out to the console.

  • 03:14

    But, anyhow, you come in here, you hook these up, and typically there's some sort of configuration you have to do.
    But, anyhow, you come in here, you hook these up, and typically there's some sort of configuration you have to do.

  • 03:19

    There's not with the debug provider because it just writes to the debug output
    There's not with the debug provider because it just writes to the debug output

  • 03:24

    but like when we add console, you can choose some options like
    but like when we add console, you can choose some options like

  • 03:28

    what the minimum level of messages you'd like to log or whether or not to include scopes and scopes are
    what the minimum level of messages you'd like to log or whether or not to include scopes and scopes are

  • 03:36

    the path of
    the path of

  • 03:39

    sort of where you are in your app so you can push scopes and
    sort of where you are in your app so you can push scopes and

  • 03:45

    say, "Okay now we're in this this type or this method," and ASP.NET Core
    say, "Okay now we're in this this type or this method," and ASP.NET Core

  • 03:50

    will use this to indicate which API is serving your request, for example.
    will use this to indicate which API is serving your request, for example.

  • 03:56

    But most commonly you'll just use something from configuration because most providers, like the console provider, can be
    But most commonly you'll just use something from configuration because most providers, like the console provider, can be

  • 04:03

    set up using
    set up using

  • 04:05

    configuration so we can go over in our appsettings.json. If you just look at this top section, now,
    configuration so we can go over in our appsettings.json. If you just look at this top section, now,

  • 04:10

    you can see here's our configuration for how we want our console logger to work.
    you can see here's our configuration for how we want our console logger to work.

  • 04:15

    We have log levels depending on the source of the message and whether or not to include scopes and
    We have log levels depending on the source of the message and whether or not to include scopes and

  • 04:21

    it's a best practice to do the configuration in a
    it's a best practice to do the configuration in a

  • 04:24

    config file like an appsettings.json because that way you can change your logging configuration without recompiling you app.
    config file like an appsettings.json because that way you can change your logging configuration without recompiling you app.

  • 04:31

    So with AddDebug, AddConsole. Now, like I said, one of the great things about Microsoft.Extensions.Logging is
    So with AddDebug, AddConsole. Now, like I said, one of the great things about Microsoft.Extensions.Logging is

  • 04:38

    how many options there are for where you want to write things. If we take a look at the documentation,
    how many options there are for where you want to write things. If we take a look at the documentation,

  • 04:43

    and I should mention, actually, while I'm on the topic of documentation the documentation
    and I should mention, actually, while I'm on the topic of documentation the documentation

  • 04:51

    we have for ASP.NET Core logging is quite good.
    we have for ASP.NET Core logging is quite good.

  • 04:54

    So, if you go out to docs.Microsoft.com, look at ASP.NET Core,
    So, if you go out to docs.Microsoft.com, look at ASP.NET Core,

  • 05:00

    find the logging article,
    find the logging article,

  • 05:02

    it'll have all the information from this video plus some more details, so I'd encourage you to go check that out.
    it'll have all the information from this video plus some more details, so I'd encourage you to go check that out.

  • 05:08

    But if we go down to built in logging providers, you can see that out-of-the-box, ASP.NET Core has providers for console
    But if we go down to built in logging providers, you can see that out-of-the-box, ASP.NET Core has providers for console

  • 05:15

    logging, debug logging, EventSource, Event Log, Trace Source, and even Azure AppService which is pretty cool. Azure AppService logging,
    logging, debug logging, EventSource, Event Log, Trace Source, and even Azure AppService which is pretty cool. Azure AppService logging,

  • 05:24

    if we hook that up, I have a blog post that talks more about this
    if we hook that up, I have a blog post that talks more about this

  • 05:28

    so I'd encourage you to go check this out as well
    so I'd encourage you to go check this out as well

  • 05:30

    and I'll put the link to this blog post down in the comments below this video, but
    and I'll put the link to this blog post down in the comments below this video, but

  • 05:35

    you can
    you can

  • 05:36

    hook up AddAzureWebAppDiagnostics (it's another AddProvider extension method),
    hook up AddAzureWebAppDiagnostics (it's another AddProvider extension method),

  • 05:43

    optionally you provide some settings about what format you'd like the messages in (but this is not required),
    optionally you provide some settings about what format you'd like the messages in (but this is not required),

  • 05:48

    and then when you deploy your application as an Azure AppService, we'll
    and then when you deploy your application as an Azure AppService, we'll

  • 05:53

    automatically start collecting those logs if logging is enabled for your AppService, and you can enable it
    automatically start collecting those logs if logging is enabled for your AppService, and you can enable it

  • 05:58

    through either the portal in the
    through either the portal in the

  • 06:01

    diagnostic logs blade or just using the Azure CLI.
    diagnostic logs blade or just using the Azure CLI.

  • 06:05

    Once logging is enabled for your AppService, if this provider is registered, then whatever
    Once logging is enabled for your AppService, if this provider is registered, then whatever

  • 06:11

    a logger generated by this ILoggerFactory writes a message, it'll be streamed to the application logs
    a logger generated by this ILoggerFactory writes a message, it'll be streamed to the application logs

  • 06:18

    which you can see either in the portal or, again, using the
    which you can see either in the portal or, again, using the

  • 06:21

    CLI. Like I said, I'll include a link to this blog so you can read more of these details.
    CLI. Like I said, I'll include a link to this blog so you can read more of these details.

  • 06:26

    But if you're deploying into Azure App Service, this is a nice provider to know about.
    But if you're deploying into Azure App Service, this is a nice provider to know about.

  • 06:31

    Another provider that's nice, though, (like I said,
    Another provider that's nice, though, (like I said,

  • 06:33

    it's not just our first party ones, there are a lot of third-party providers
    it's not just our first party ones, there are a lot of third-party providers

  • 06:37

    because of the extensible nature of Microsoft.Extensions.Logging), Serilog is a big one because
    because of the extensible nature of Microsoft.Extensions.Logging), Serilog is a big one because

  • 06:42

    Serilog has so many sinks you can use. If you go look on their GitHub page github.com/serilog,
    Serilog has so many sinks you can use. If you go look on their GitHub page github.com/serilog,

  • 06:48

    here's a list of their available Serilog syncs.
    here's a list of their available Serilog syncs.

  • 06:51

    These are all the places Serilog can write. So you've got everywhere from SQL Server
    These are all the places Serilog can write. So you've got everywhere from SQL Server

  • 06:57

    to Azure Table Storage to AWS CloudWatch, to Elasticsearch and
    to Azure Table Storage to AWS CloudWatch, to Elasticsearch and

  • 07:03

    so, really, about any place you want to write logging messages
    so, really, about any place you want to write logging messages

  • 07:07

    from your ASP.NET Core app, you can do it either with a built-in provider or through the Serilog provider.
    from your ASP.NET Core app, you can do it either with a built-in provider or through the Serilog provider.

  • 07:15

    If we come back over to my demo here, you can see I'm actually setting up a Serilog
    If we come back over to my demo here, you can see I'm actually setting up a Serilog

  • 07:20

    provider here by creating a new LoggerConfiguration (which is the Serilog
    provider here by creating a new LoggerConfiguration (which is the Serilog

  • 07:24

    configuration object) and then, as with most providers,
    configuration object) and then, as with most providers,

  • 07:27

    you can configure Serilog, either programmatically by calling .WriteTo and then the sink you want to use (like here
    you can configure Serilog, either programmatically by calling .WriteTo and then the sink you want to use (like here

  • 07:33

    I'm saying we're going to use Azure Table Storage).
    I'm saying we're going to use Azure Table Storage).

  • 07:35

    If I wanted to use Amazon CloudWatch it's it's similarly simple to do programmatically. Or you can do it through configuration.
    If I wanted to use Amazon CloudWatch it's it's similarly simple to do programmatically. Or you can do it through configuration.

  • 07:43

    So I can say .ReadFrom.Configuration, and I pass my configuration object.
    So I can say .ReadFrom.Configuration, and I pass my configuration object.

  • 07:47

    So if we go back to appsettings.json,
    So if we go back to appsettings.json,

  • 07:53

    you can see down here is our Serilog configuration. By default, Serilog will look for a configuration section called Serilog
    you can see down here is our Serilog configuration. By default, Serilog will look for a configuration section called Serilog

  • 08:00

    and it gets minimum level to log. It also has a WriteTo section where I can list
    and it gets minimum level to log. It also has a WriteTo section where I can list

  • 08:05

    the sinks that I plan to use, so in here I'm using the LiterateConsole sink.
    the sinks that I plan to use, so in here I'm using the LiterateConsole sink.

  • 08:10

    LiterateConsole is a very cool sink. It's a console sink
    LiterateConsole is a very cool sink. It's a console sink

  • 08:13

    (so it writes to the console),
    (so it writes to the console),

  • 08:15

    but it uses structured logging. So the idea of structured logging is worth explaining a little bit because it's really powerful.
    but it uses structured logging. So the idea of structured logging is worth explaining a little bit because it's really powerful.

  • 08:23

    Structured logging means that when we log a
    Structured logging means that when we log a

  • 08:26

    message, in addition to just logging the message itself, pieces of data from within the message will be logged
    message, in addition to just logging the message itself, pieces of data from within the message will be logged

  • 08:32

    separately in a strongly typed way so that they can be easily queried later. Let me show you an example of how this might look.
    separately in a strongly typed way so that they can be easily queried later. Let me show you an example of how this might look.

  • 08:39

    So here in my CustomersController, I have a logger.
    So here in my CustomersController, I have a logger.

  • 08:43

    Then I call LogInformation. This is how you might log a piece of information using the Microsoft.Extensions.Logging framework.
    Then I call LogInformation. This is how you might log a piece of information using the Microsoft.Extensions.Logging framework.

  • 08:49

    I then provide the message that is going to be logged, but notice that I have these parameters in curly braces here. I have the HTTP
    I then provide the message that is going to be logged, but notice that I have these parameters in curly braces here. I have the HTTP

  • 08:57

    verb (the method, like GET, POST, whatever)
    verb (the method, like GET, POST, whatever)

  • 09:01

    that was used, and I also have a custom message that I'm just getting out of resources here
    that was used, and I also have a custom message that I'm just getting out of resources here

  • 09:06

    that explains the path that the request went to. And then, over here, we have
    that explains the path that the request went to. And then, over here, we have

  • 09:13

    parameters, which will fill in to format this string
    parameters, which will fill in to format this string

  • 09:16

    but because these are named curly brace parameters, Serilog recognizes these as
    but because these are named curly brace parameters, Serilog recognizes these as

  • 09:22

    interesting pieces of data. So when Serilog logs our message, it'll log the formatted string which is human readable,
    interesting pieces of data. So when Serilog logs our message, it'll log the formatted string which is human readable,

  • 09:29

    but it will also log (if the sink supports it),
    but it will also log (if the sink supports it),

  • 09:33

    these pieces of data in a standalone way
    these pieces of data in a standalone way

  • 09:35

    so you'll have a method name of,
    so you'll have a method name of,

  • 09:37

    you know, POST or GET or whatever so then let's say I
    you know, POST or GET or whatever so then let's say I

  • 09:40

    log this to Elasticsearch which, of course, would support all of those structured pieces of data. I could then search
    log this to Elasticsearch which, of course, would support all of those structured pieces of data. I could then search

  • 09:47

    through all of my logging events, all my
    through all of my logging events, all my

  • 09:49

    diagnostics for instances where method name is equal to PORT or PUT and so it makes it really easy
    diagnostics for instances where method name is equal to PORT or PUT and so it makes it really easy

  • 09:55

    to query on interesting data in your logging messages
    to query on interesting data in your logging messages

  • 09:59

    without having everything just be a string that you have to parse through. So, as much as possible when you're using
    without having everything just be a string that you have to parse through. So, as much as possible when you're using

  • 10:05

    Microsoft.Extensions.Logging, I encourage you to really make use of this structured logging feature because it's very powerful and all it
    Microsoft.Extensions.Logging, I encourage you to really make use of this structured logging feature because it's very powerful and all it

  • 10:12

    requires is that you're careful about the way you set up your messages so that interesting pieces of data are called out with curly braces
    requires is that you're careful about the way you set up your messages so that interesting pieces of data are called out with curly braces

  • 10:19

    that will be stored separately
    that will be stored separately

  • 10:22

    Now, to show how we're using this in here, you'll notice that I'm just
    Now, to show how we're using this in here, you'll notice that I'm just

  • 10:26

    getting an ILogger in through our constructor, so all of the logging
    getting an ILogger in through our constructor, so all of the logging

  • 10:33

    infrastructure is provided through dependency injection in ASP.NET Core. Now, if you look in my Startup.cs, you'll notice
    infrastructure is provided through dependency injection in ASP.NET Core. Now, if you look in my Startup.cs, you'll notice

  • 10:40

    we actually don't even register anything in ConfigureServices.
    we actually don't even register anything in ConfigureServices.

  • 10:44

    There's a lot of stuff being registered here,
    There's a lot of stuff being registered here,

  • 10:45

    but nothing related to logging. The reason for that is because ASP.NET Core will automatically provide logging services as part of its base functionality.
    but nothing related to logging. The reason for that is because ASP.NET Core will automatically provide logging services as part of its base functionality.

  • 10:53

    So in Configure, we can request the ILoggerFactory that will automatically be injected via dependency injection.
    So in Configure, we can request the ILoggerFactory that will automatically be injected via dependency injection.

  • 11:01

    Similarly, then, after we've configured it,
    Similarly, then, after we've configured it,

  • 11:04

    in our controllers, we can request an ILogger and that will be provided. Now you notice that the ILogger is generic.
    in our controllers, we can request an ILogger and that will be provided. Now you notice that the ILogger is generic.

  • 11:11

    What we pass here is going to be the category.
    What we pass here is going to be the category.

  • 11:13

    So, typically you're going to pass the class
    So, typically you're going to pass the class

  • 11:15

    which is doing the logging because this will be the category which log messages are categorized into.
    which is doing the logging because this will be the category which log messages are categorized into.

  • 11:22

    So it's a nice way of keeping separate things that come from one controller versus another controller.
    So it's a nice way of keeping separate things that come from one controller versus another controller.

  • 11:26

    So that's why within the CustomersController, I get an ILogger. Now, you can create ILoggers
    So that's why within the CustomersController, I get an ILogger. Now, you can create ILoggers

  • 11:33

    explicitly and, if you do that, you can request whatever category you want, but this is a nice,
    explicitly and, if you do that, you can request whatever category you want, but this is a nice,

  • 11:38

    just sort of a nice standard way of doing it. You can actually see here in this sample, I have some custom middleware
    just sort of a nice standard way of doing it. You can actually see here in this sample, I have some custom middleware

  • 11:46

    that's just defined right in-line (it doesn't have its own class). So to create a logger to use in there,
    that's just defined right in-line (it doesn't have its own class). So to create a logger to use in there,

  • 11:52

    I just call LoggerFactory.CreateLogger and then I specify the category that I want. And so here's another way of doing this.
    I just call LoggerFactory.CreateLogger and then I specify the category that I want. And so here's another way of doing this.

  • 11:58

    Then in here, in this middleware, whenever I log,
    Then in here, in this middleware, whenever I log,

  • 12:01

    this string is what will be used as the category. And again, in here,
    this string is what will be used as the category. And again, in here,

  • 12:07

    you know, you can see I'm calling LogInformation just the same as we did before.
    you know, you can see I'm calling LogInformation just the same as we did before.

  • 12:12

    Now one other thing to point out also is that in appsettings.json, you can see I'm actually referring to some other
    Now one other thing to point out also is that in appsettings.json, you can see I'm actually referring to some other

  • 12:17

    some other parameters which I didn't define like RequestId and Level. These things are automatically
    some other parameters which I didn't define like RequestId and Level. These things are automatically

  • 12:23

    provided by ASP.NET Core, as well. If you look at the blog post I was referring to earlier,
    provided by ASP.NET Core, as well. If you look at the blog post I was referring to earlier,

  • 12:29

    you can see down here where I sent some information to Elasticsearch, it gets all of those parameters. You can see that ASP.NET Core
    you can see down here where I sent some information to Elasticsearch, it gets all of those parameters. You can see that ASP.NET Core

  • 12:36

    out-of-the-box is going to include parameters for request path (which is going to be the path the request went to), request Id
    out-of-the-box is going to include parameters for request path (which is going to be the path the request went to), request Id

  • 12:43

    (which is a unique Id for correlating different
    (which is a unique Id for correlating different

  • 12:46

    events that happened while processing a single HTTP request), action name action ID,
    events that happened while processing a single HTTP request), action name action ID,

  • 12:52

    task Id, SourceContext, these are all things which are included by default either by Microsoft.Extensions.Logging or
    task Id, SourceContext, these are all things which are included by default either by Microsoft.Extensions.Logging or

  • 12:59

    ASP.NET Core.
    ASP.NET Core.

  • 13:01

    So you could refer to these when you're creating a template path that you would like your provider (like the console provider or
    So you could refer to these when you're creating a template path that you would like your provider (like the console provider or

  • 13:08

    one of the Serilog sinks) to use so these can then be be
    one of the Serilog sinks) to use so these can then be be

  • 13:13

    included in your messages.
    included in your messages.

  • 13:17

    I've gone through that really quickly.
    I've gone through that really quickly.

  • 13:18

    To wrap up let me go ahead and just kick this app off
    To wrap up let me go ahead and just kick this app off

  • 13:22

    and we'll see some logging happening. Since I've configured the LiterateConsole, we'll just see it right in our console output.
    and we'll see some logging happening. Since I've configured the LiterateConsole, we'll just see it right in our console output.

  • 13:28

    This is just a very simple web API. The app itself is not super interesting but you can see here all
    This is just a very simple web API. The app itself is not super interesting but you can see here all

  • 13:33

    that logging happening.
    that logging happening.

  • 13:35

    And you can see that the output template is being used to to format the messages
    And you can see that the output template is being used to to format the messages

  • 13:41

    so I'm getting things like the request Id,
    so I'm getting things like the request Id,

  • 13:44

    if it exists, the level, the timestamp, and then, over here,
    if it exists, the level, the timestamp, and then, over here,

  • 13:48

    If I go ahead and call the GET method that we were looking at previously,
    If I go ahead and call the GET method that we were looking at previously,

  • 13:54

    you can see here that we (here it is), here is that
    you can see here that we (here it is), here is that

  • 13:59

    message that I was showing that's using structured logging so 'GET' and 'Getting customers' are actually highlighted in cyan here by the
    message that I was showing that's using structured logging so 'GET' and 'Getting customers' are actually highlighted in cyan here by the

  • 14:07

    LiterateConsole sink because it recognizes those as being string parameters that are part of the structured message.
    LiterateConsole sink because it recognizes those as being string parameters that are part of the structured message.

  • 14:14

    So when this goes to something like
    So when this goes to something like

  • 14:16

    Table Storage or Elasticsearch, these will be called out as separate string parameters that we could query on. In the LiterateConsole, what it
    Table Storage or Elasticsearch, these will be called out as separate string parameters that we could query on. In the LiterateConsole, what it

  • 14:23

    does is just sort of color code them to make it easy to spot things that are maybe particularly interesting or that,
    does is just sort of color code them to make it easy to spot things that are maybe particularly interesting or that,

  • 14:30

    you know, are especially relevant to
    you know, are especially relevant to

  • 14:33

    what we're looking at.
    what we're looking at.

  • 14:35

    And so you also can see here some of the information from that custom middleware about how long
    And so you also can see here some of the information from that custom middleware about how long

  • 14:43

    things took. And that's not even really necessary since ASP.NET Core also logs similar messages, but I included it here
    things took. And that's not even really necessary since ASP.NET Core also logs similar messages, but I included it here

  • 14:49

    just as a way to demonstrate some middleware in a separate sample.
    just as a way to demonstrate some middleware in a separate sample.

  • 14:53

    But this is what the LiterateConsole output looks like. Again,
    But this is what the LiterateConsole output looks like. Again,

  • 14:57

    this is a Serilog sink because I've plugged Serilog into Microsoft.Extensions.Logging
    this is a Serilog sink because I've plugged Serilog into Microsoft.Extensions.Logging

  • 15:03

    through their provider and,
    through their provider and,

  • 15:05

    in general, this is just a super flexible way of logging in your asp.net core apps. I hope this has been helpful.
    in general, this is just a super flexible way of logging in your asp.net core apps. I hope this has been helpful.

  • 15:12

    Thanks!
    Thanks!

All

ASP.NET Core Logging

20,749 views

Video Language:

  • English

Caption Language:

  • English (en)

Accent:

  • English (US)

Speech Time:

89%
  • 13:41 / 15:14

Speech Rate:

  • 184 wpm - Fast

Category:

  • Science & Technology

Tags :

Intro:

Hi, this is Mike Rousos from the .NET Customer Success Team. I'm going to talk today briefly about logging in ASP.NET Core.
So, if you have an ASP.NET Core app and you want to log some diagnostics,
you're typically going to be using the Microsoft.Extensions.Logging package. Let me hop over to NuGet and show that to you.
Microsoft.Extensions.Logging is what you're looking for.
You won't have to install this, typically, because it's already included in the package references for all of our ASP.NET Core
templates, but this is the package that you use and, like all, Microsoft.Extensions packages,
there's nothing in here specific to ASP.NET Core. This just
depends on .NET Standard 1.1, so you could just as easily
use this logging framework in a .NET Core console app, .NET Framework app, UWP, just the same as you would in
ASP.NET Core.. But, coming back to how it works in ASP.NET Core,. when you look at your ASP.NET Core app, you'll notice that in the templates our configure method in Startup.cs
will take an ILoggerFactory. This logger factory is what produces logger objects which we use to log events.
In the configure method, though, we need to set it up with all of the providers we want to use
for writing those logged messages to different endpoints. Now, one of the great things about the Microsoft.Extensions.Logging framework
used in ASP.NET Core is its flexibility and its extensibility.
By default, you'll have an .AddDebug which adds a debug provider so that we write to debug output.
And you typically also have an .AddConsole. as well in your. template that you start with and this will just write debug

Video Vocabulary

/ˌikˈsten(t)SH(ə)n/

adjective noun

Adding extra length. part added to extend something.

/ˈtemplət/

noun other

shaped piece of rigid material used as pattern for processes. Something used as a model to produce many copies.

/ˈref(ə)rəns/

noun other verb

action of mentioning or alluding to something. A letter of recommendation, e.g. for a job. To cite a piece of research in speech or writing.

/ˈmesij/

noun other verb

verbal written or recorded communication. Ideas or themes in a story, book, or film. To communicate using text.

/ˈpakij/

adjective noun verb

Presented as one item but includes several. Box or container items are placed in for mailing. put into box or wrapping.

/kənˈfiɡyər/

verb

arrange or put together in particular form or configuration.

/ˈlo͝okiNG/

adjective verb

having specified appearance. To appear to be when you look at them; seem.

/dəˈpend/

verb

Be controlled or determined by..

verb

To make something appear.

/ˈdif(ə)rənt/

adjective

Not of the same kind; unlike other things.

verb

To make someone feel better in times of distress.

noun other verb

material thing. Goals or purposes of particular plans or activities. To disagree; to protest against an idea or plan.

/ˌdīəɡˈnästik/

adjective noun

concerned with diagnosis of illness etc.. distinctive symptom or characteristic.

/inˈstôl/

verb

To set up equipment so that it is ready to use.

/prəˈvīdər/

noun other

person or thing that provides something. Companies or group that offer a particular service.