<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>.net core application &#8211; ASP.NET Hosting Reviews and Guides</title>
	<atom:link href="https://topreviewhostingasp.net/tag/net-core-application/feed/" rel="self" type="application/rss+xml" />
	<link>https://topreviewhostingasp.net</link>
	<description>Help you to find best ASP.NET Core Hosting</description>
	<lastBuildDate>Mon, 06 Mar 2023 04:20:05 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	

<image>
	<url>https://topreviewhostingasp.net/wp-content/uploads/2017/01/cropped-trhaico-32x32.png</url>
	<title>.net core application &#8211; ASP.NET Hosting Reviews and Guides</title>
	<link>https://topreviewhostingasp.net</link>
	<width>32</width>
	<height>32</height>
</image> 
	<item>
		<title>Application Insights .NET Core Application</title>
		<link>https://topreviewhostingasp.net/application-insights-net-core-application/</link>
					<comments>https://topreviewhostingasp.net/application-insights-net-core-application/#respond</comments>
		
		<dc:creator><![CDATA[Jacques Hunt]]></dc:creator>
		<pubDate>Mon, 06 Mar 2023 04:18:21 +0000</pubDate>
				<category><![CDATA[Hosting Tips]]></category>
		<category><![CDATA[.net core application]]></category>
		<category><![CDATA[asp net core]]></category>
		<category><![CDATA[asp net core tips]]></category>
		<category><![CDATA[asp net core tutorial]]></category>
		<category><![CDATA[c# application logs]]></category>
		<guid isPermaLink="false">https://topreviewhostingasp.net/?p=3467</guid>

					<description><![CDATA[So why would you ever log to Application Insights AND File log at the same time? Well, if you are hosting your own applications on your own machine, it can be great to have a file version of what’s happened. The file will be updated immediately, whereas Application Insights are sometimes up to 5 minutes [&#8230;]]]></description>
										<content:encoded><![CDATA[
<p>So why would you ever log to Application Insights AND File log at the same time? Well, if you are hosting your own applications on your own machine, it can be great to have a file version of what’s happened. The file will be updated immediately, whereas Application Insights are sometimes up to 5 minutes behind.<br />Also, it gives you the opportunity to log at different levels. Application Insights is not cheap, so having Application Insights log only warnings and errors, but the file logging debug can be a money saver.<br />And, when developing, the file log is far superior to Application Insights.</p>



<p><strong>STEP 1: THE NUGET PACKAGES</strong></p>



<p>You need the following packages:</p>



<ul>
<li><a href="https://www.nuget.org/packages/Microsoft.Extensions.Logging/" target="_blank" rel="noreferrer noopener">Microsoft.Extensions.Logging</a></li>
<li><a href="https://www.nuget.org/packages/Serilog.Extensions.Logging.File/" target="_blank" rel="noreferrer noopener">Serilog.Extensions.Logging.File</a></li>
</ul>



<p><strong>STEP 2: THE CONFIGURATION</strong></p>



<p>This will configure the logging:</p>



<pre class="wp-block-code"><code>"ApplicationInsights": {
    "InstrumentationKey": "[The instrumentation key]"
  },
"Logging": {
    "PathFormat": "[The path and file format used in file logging, e.g.: c:\\log-{Date}.txt]",
    "LogLevel": {
      "Default": "Information"
    },
    "ApplicationInsightsLoggerProvider": {
      "LogLevel": {
        "Default": "Warning"
      }
    }
  }</code></pre>



<p>The “Logging” section configures the different log levels for file and Application Insights.</p>



<p><strong>STEP 3: THE EXTENSION METHOD</strong></p>



<p>This method allows you to add logging easily:</p>



<pre class="wp-block-code"><code>using Microsoft.ApplicationInsights.AspNetCore.Extensions;
 
namespace MyCode
{
    public static class WebApplicationBuilderExtensions
    {
        public static void AddLogging(this WebApplicationBuilder builder)
        {
            // Add file logging
            builder.Host.ConfigureLogging(logging =&gt;
                {
                    logging.AddFile(builder.Configuration.GetSection("Logging"));
                }
            );
            // Add Application Insights Logging
            var options = new ApplicationInsightsServiceOptions();
            options.InstrumentationKey = builder.Configuration["ApplicationInsights:InstrumentationKey"];
            builder.Services.AddApplicationInsightsTelemetry(options);
        }
    }
}</code></pre>



<p><strong>STEP 4: CALL THE METHOD WHEN BUILDING YOUR APPLICATION</strong></p>



<p>This is an example where I configure my logging:</p>



<pre class="wp-block-code"><code>using System;
using Microsoft.AspNetCore.Builder;
using Microsoft.Extensions.Hosting;
 
var webApplicationOptions = new WebApplicationOptions();
var builder = WebApplication.CreateBuilder(webApplicationOptions);
builder.AddLogging();
...
...
...
builder.Build();</code></pre>



<p>&nbsp;</p>
]]></content:encoded>
					
					<wfw:commentRss>https://topreviewhostingasp.net/application-insights-net-core-application/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
