---
title: "Configure .NET Core"
slug: "errors-and-logs-configure-net-core"
description: "Easily configure StackifyLib for .NET applications. Learn step-by-step setup with ASP.NET, console, and new .NET Core logging API. Log errors and capture web request details."
updated: 2018-06-15T14:59:51Z
published: 2018-06-15T14:59:51Z
---

> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stackify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Logging with .NET Core

## Step 1: Add StackifyLib nuget package and basic configuration

No matter which logging framework you are using, you need to add [StackifyLib](https://www.nuget.org/packages/StackifyLib/) and add the Stackify.ApiKey to your config file.

### Set Stackify Configuration settings

Because .NET core allows a wide variety of configuration options, how you configure the key could vary wildly. This is just one example of how to do it with the standard appsettings.json file.

```json
{
 "Logging": {
   "IncludeScopes": false,
   "LogLevel": {
     "Default": "None",
     "System": "None",
     "Microsoft": "None",
     "Microsoft.AspNetCore.Mvc.Internal":  "None" 
   }
 },
 "Stackify": {
   "ApiKey": "your key goes here",
   "AppName": "CoreWebApp", //optional
   "Environment": "Dev" //optional
 }
}
```

### ASP.NET Core

For ASP.NET you also want to add an additional [StackifyLib.AspNetCore nuget package](https://www.nuget.org/packages/StackifyLib.AspNetCore/). It enables capturing web request details for exceptions. It is not required, but highly recommended. In your Startup.cs Configure() event you need to add `app.ConfigureStackifyLogging(Configuration);` as shown here. This assumes that in the Startup constructor method you are also creating your configuration object.

```csharp
using StackifyLib;
...
public IConfigurationRoot Configuration { get; }

public Startup(IHostingEnvironment env)
{
	var builder = new ConfigurationBuilder()
		.SetBasePath(env.ContentRootPath)
		.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
		.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
		.AddEnvironmentVariables();
	Configuration = builder.Build();

	
	StackifyLib.Config.Environment = env.EnvironmentName; //optional
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
	app.ConfigureStackifyLogging(Configuration); //This is critical!!
	app.UseMvc();
}
```

### Using with a Console application

There is no Startup class like there is for ASP.NET and we aren't worried about collecting web request details. So the configuration is slightly different and there is no need for the extra nuget package.

```csharp
var builder = new ConfigurationBuilder()
	.SetBasePath(env.ContentRootPath)
	.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
	.AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true)
	.AddEnvironmentVariables();

Configuration = builder.Build();
Configuration.ConfigureStackifyLogging(); //This applies the settings
```

## Step 2: Add your logging provider library

**Standard logging libraries** Stackify supports the standard third party libraries: log4net, NLog, Serilog For all of these there is a corresponding nuget package required to setup the logging appender/target/provider. Please review these related docs for how to install and configure them. Please note that any reference in them to configure the Stackify.ApiKey and such is specific to non .NET Core, that part needs to be done as mentioned here.

- [Errors And Logs With Log4net](/docs/errors-and-logs-log4net)
- [Errors And Logs With NLog](/docs/errors-and-logs-configure-nlog)
- [Stackify Serilog](/docs/errors-and-logs-serilog)

## Using the New .NET Core Logging API

For .NET Core you can also use the new logging API that is based around ILoggerFactory. We would recommend also checking out this blog post on the topic: [.NET Core LoggerFactory: How to use it correctly and lots of tips!](https://stackify.com/net-core-loggerfactory-use-correctly/)

> NOTE: If you are using one of the standard third party libraries, there is no reason to do this also!

Install the nuget package called [StackifyLib.CoreLogger](https://www.nuget.org/packages/StackifyLib.CoreLogger/) and modify your Startup class to register the provider. For an ASP.NET app you also still need the [StackifyLib.AspNetCore](https://www.nuget.org/packages/StackifyLib.AspNetCore/) package as well.

```csharp
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
	loggerFactory.AddStackify(); //add the provider

	app.ConfigureStackifyLogging(Configuration); //configure settings and ASP.NET exception hooks

	app.UseMvc();
}
```

## Step 3: Log some stuff!

- [Errors and Logs: Capturing Web Request Details](/docs/errors-logs-capturing-web-request-details)
- [Logs: Dashboard](/docs/logs-dashboard)

If you are still having issues logging to Retrace, please follow the [Troubleshoot: Errors and Logs .NET Configurations](/docs/troubleshoot-errors-and-logs-net-configurations) guide to address common issues.
