Skip to content

Commit 2573e14

Browse files
updated post to use aws cli
1 parent 2d7547a commit 2573e14

File tree

3 files changed

+113
-42
lines changed

3 files changed

+113
-42
lines changed

content/assets/index.json

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -73,18 +73,18 @@
7373
"path": "./content/docs/clients/dotnet/guides/console-apps-example.md"
7474
},
7575
"logging-with-generic-host": {
76-
"title": "Web Server Example",
76+
"title": "Logging With Generic Host",
7777
"order": 3,
7878
"preview": "Microsoft provides a useful tool for logging events called …",
79-
"content": "\n\nMicrosoft provides a useful tool for logging events called `Microsoft.Extensions.Logging`. You can read up on how logging works with .NET Core here, but we'll cover how to set up Exceptionless as a logging provider to be used as a generic host. \n\n",
79+
"content": "\n\nMicrosoft provides a useful tool for logging events called `Microsoft.Extensions.Logging`. You can read up on [how logging works with .NET Core here](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-5.0), but we'll cover how to set up Exceptionless as a logging provider to be used as a generic host. \n\nTo get started, you'll need to make sure you update your `appsettings.json` file for your project. Here's an example configuration that will allow you to use Exceptionless with .NET Core's generic host: \n\n```\n\"Exceptionless\": {\n \"ApiKey\": \"YOUR API KEY\"\n },\n \"Logging\": {\n \"IncludeScopes\": false,\n \"LogLevel\": {\n \"Default\": \"Debug\",\n \"System\": \"Information\",\n \"Microsoft\": \"Information\"\n }\n }\n```\n\nWith that added, you can add the Exceptionless namespace to any file in your project with `using Exceptionless;`. This then allows you to utilize Exceptionless with dependency injection, or as we're covering here, as a generic host. \n\nIn your `Startup` method, you can read in your configuration file like this: \n\n```\nvar builder = new ConfigurationBuilder()\n .SetBasePath(env.ContentRootPath)\n .AddJsonFile(\"appsettings.json\", optional: true, reloadOnChange: true)\n .AddEnvironmentVariables();\n Configuration = builder.Build();\n```\n\nThis tells .NET Core to use whatever settings you've provided in the `appsettings.json` file for the logger (it also sets up some other configurations). To ensure Exceptionless is used for logging, you will need to update the `ConfigureServices` method to this: \n\n```\nservices.AddLogging(b => b\n .AddConfiguration(Configuration.GetSection(\"Logging\"))\n .AddDebug()\n .AddConsole()\n .AddExceptionless());\n```\n\nThis is adding debugging capabilities, console logging, and Exceptionless to your generic host logging configuration.\n\nIf you are using a generic host in a web server application, you may want to capture more information about HTTP requests automatically. To do this, you'll need to edit the `ConfigureServices` method to include the following line: \n\n`services.AddHttpContextAccessor();`\n\nFinally, you'll need to tell the app itself to use Exceptionless. You can do this in your `Configure` method liket his: \n\n`app.useExceptionless(Configuration);`\n\nNow, you have access to send logs, exceptions, and messages to Exceptionless automatically through the generic host configuration. If you'd like to see a full, detailed example, [we have that here](https://github.com/exceptionless/Exceptionless.Net/blob/9e91a51c36d03fcc3bee79a8b6eaee3034ac78b4/samples/Exceptionless.SampleAspNetCore/Startup.cs).\n\n### Exceptionless Configuration Options \n\nOne of the nice things about configuring Exceptionless through `appsettings.json` is you can set up some defaults that will apply to all events sent through to Exceptionless. Let's explore what that might look like. In your `appsettings.json` file, you can add the following to your `Exceptionless` property: \n\n```\n \"DefaultData\": {\n \"JSON_OBJECT\": \"{ \\\"Name\\\": \\\"John Doe\\\" }\",\n \"Boolean\": true,\n \"Number\": 1,\n \"Array\": \"1,2,3\"\n},\n```\n\nThis is a very simple object that encapsulates default data that will be sent to Exceptionless with every event. The `DefaultData` property can take in any property keys you'd like to pass in. The property values must be strings, booleans, numbers, or arrays. As you can see in the example, a JSON object can simply be stringified. \n\nIn addition to the `DefaultData` property, you can include `DefaultTags` and `Settings`. To include `DefaultTags`, add the following: \n\n```\n\"DefaultTags\": [ \"MySpecialTag\" ]\n```\n\nAs you can probably tell, you can pass in as many tags as you'd like as an array of strings. \n\nTo add custom settings, you would do something like this: \n\n```\n\"Settings\": {\n \"FeatureXYZEnabled\": false \n} \n```\n\nThe `Settings` property can take any keys you'd like. The values associated with those keys must be strings, numbers, or booleans.\n\nYou can, of course, customize the default logging, but that is outside the Exceptionless configuration. If you'd like to customize the way things are logged when using the generic host, [follow this guide](https://docs.microsoft.com/en-us/aspnet/core/fundamentals/logging/?view=aspnetcore-5.0#configure-logging). \n\n---\n\n[Next > Sending Events](../sending-events.md) {.text-right}",
8080
"basename": "logging-with-generic-host",
8181
"path": "./content/docs/clients/dotnet/guides/logging-with-generic-host.md"
8282
},
8383
"web-server-example": {
8484
"title": "Web Server Example",
8585
"order": 2,
8686
"preview": "Exceptionless runs great in all sorts of environments. Let's take a …",
87-
"content": "\n\nExceptionless runs great in all sorts of environments. Let's take a look at how you might set up Exceptionless to work with your .NET web server. \n\nTo get started, be sure to include the Exceptionless namespace wherever you plan to use it. You can do that like this: `using Exceptionless;`\n\nThe simplest example of using Exceptionless in your web server is to include a try/catch block that leverages Exceptionless in the catch. It might look something like this: \n\n```csharp\n[HttpGet(\"{id}\")]\npublic ActionResult<User> GetUser(string id)\n{\n try {\n var user = userService.GetUser(id);\n return Ok(user);\n } catch (Exception ex) {\n ex.ToExceptionless().SetProperty(\"UserId\", id).Submit();\n return NotFound();\n }\n}\n```\n\nShould the request to `FetchUser()`, or whatever your method is, happen to throw, the Exceptionless client will pick it up and send the exception to your dashboard. \n\nOf course, Exceptionless is more than just error handling. You can leverage any of the Exceptionless event methods [documented here](sending-events.md) through the client interface. \n\nExceptionless can be configured as a generic host for your web server. In your `Startup.cs` file, you would include the following within the `ConfigureServices` method: \n\n```csharp\nservices.AddHttpContextAccessor();\n```\n\nBy adding this helper method, Exceptionless is able to gather more information about the request including the API endpoint that threw the error, user-agent information, and more. \n\nThen in your `Configure` method, you would add: \n\n```csharp\napp.UseExceptionless(Configuration);\n```\n\nTo get access to your Exceptionless configuration (which we'll explain next), you'll need to do create a `builder` variable in your `Startup` method and build the configuration like this: \n\n```csharp\nvar builder = new ConfigurationBuilder()\n .SetBasePath(env.ContentRootPath)\n .AddJsonFile(\"appsettings.json\", optional: true, reloadOnChange: true)\n .AddEnvironmentVariables();\nConfiguration = builder.Build();\n```\n\nThis gives your server application access to any configuration you've set in your `appsettings.json` file. And that's exactly where we will configure Exceptionless. So, go ahead and open that file and we can create some configuration for your Exceptionless client: \n\n```json\n \"Exceptionless\": {\n \"ApiKey\": \"YOUR API KEY\",\n \"ServerUrl\": \"http://localhost:50000\",\n \"DefaultData\": {\n \"JSON_OBJECT\": \"{ \\\"Name\\\": \\\"Alice\\\" }\",\n \"Boolean\": true,\n \"Number\": 1,\n \"Array\": \"1,2,3\"\n },\n \"DefaultTags\": [ \"SOME_TAG\" ],\n \"Settings\": {\n \"FeatureXYZEnabled\": false \n } \n},\n```\n\nYou will only pass in the `ServerUrl` if you are self-hosting Exceptionless. You'll use this to point to your correct URL. The `DefaultData` is metadata you'd like associated with every event you send to Exceptionless. \n\nWith this configured, you can now call the Exceptionless client from anywhere in your server application without first defining the client. \n\nThis is just one example of one platform Exceptionless supports. But Exceptionless supports a wide range of platforms. For a full list, see the [supported platforms page here](supported-platforms.md).\n\n---\n\n[Next > Sending Events](../sending-events.md) {.text-right}\n",
87+
"content": "\n\nExceptionless runs great in all sorts of environments. Let's take a look at how you might set up Exceptionless to work with your .NET web server. \n\nTo get started, be sure to include the Exceptionless namespace wherever you plan to use it. You can do that like this: `using Exceptionless;`\n\nThe simplest example of using Exceptionless in your web server is to include a try/catch block that leverages Exceptionless in the catch. It might look something like this: \n\n```csharp\n[HttpGet(\"{id}\")]\npublic ActionResult<User> GetUser(string id)\n{\n try {\n var user = userService.GetUser(id);\n return Ok(user);\n } catch (Exception ex) {\n ex.ToExceptionless().SetProperty(\"UserId\", id).Submit();\n return NotFound();\n }\n}\n```\n\nShould the request to `FetchUser()`, or whatever your method is, happen to throw, the Exceptionless client will pick it up and send the exception to your dashboard. \n\nOf course, Exceptionless is more than just error handling. You can leverage any of the Exceptionless event methods [documented here](sending-events.md) through the client interface. \n\nExceptionless can be configured as a generic host for your web server. In your `Startup.cs` file, you would include the following within the `ConfigureServices` method: \n\n```csharp\nservices.AddHttpContextAccessor();\n```\n\nBy adding this helper method, Exceptionless is able to gather more information about the request including the API endpoint that threw the error, user-agent information, and more. \n\nThen in your `Configure` method, you would add: \n\n```csharp\napp.UseExceptionless(Configuration);\n```\n\nTo get access to your Exceptionless configuration (which we'll explain next), you'll need to do create a `builder` variable in your `Startup` method and build the configuration like this: \n\n```csharp\nvar builder = new ConfigurationBuilder()\n .SetBasePath(env.ContentRootPath)\n .AddJsonFile(\"appsettings.json\", optional: true, reloadOnChange: true)\n .AddEnvironmentVariables();\nConfiguration = builder.Build();\n```\n\nThis gives your server application access to any configuration you've set in your `appsettings.json` file. And that's exactly where we will configure Exceptionless. So, go ahead and open that file and we can create some configuration for your Exceptionless client: \n\n```json\n \"Exceptionless\": {\n \"ApiKey\": \"YOUR API KEY\",\n \"ServerUrl\": \"http://localhost:50000\",\n \"DefaultData\": {\n \"JSON_OBJECT\": \"{ \\\"Name\\\": \\\"Alice\\\" }\",\n \"Boolean\": true,\n \"Number\": 1,\n \"Array\": \"1,2,3\"\n },\n \"DefaultTags\": [ \"SOME_TAG\" ],\n \"Settings\": {\n \"FeatureXYZEnabled\": false \n } \n},\n```\n\nYou will only pass in the `ServerUrl` if you are self-hosting Exceptionless. You'll use this to point to your correct URL. The `DefaultData` is metadata you'd like associated with every event you send to Exceptionless. \n\nWith this configured, you can now call the Exceptionless client from anywhere in your server application without first defining the client. \n\nThis is just one example of one platform Exceptionless supports. But Exceptionless supports a wide range of platforms. For a full list, see the [supported platforms page here](supported-platforms.md).\n\n---\n\n[Next > Logging With Generic Host](logging-with-generic-host.md) {.text-right}\n",
8888
"basename": "web-server-example",
8989
"path": "./content/docs/clients/dotnet/guides/web-server-example.md"
9090
},

0 commit comments

Comments
 (0)