What are the config for NewRelic ASP.NET Core appsettings.json - asp.net-core

The settings of referenced here was introduced as
Here are instructions for enabling the agent for .NET Framework and.NET Core.
https://docs.newrelic.com/docs/apm/agents/net-agent/installation/install-net-agent-windows/#app-config
It shows the following configuration:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="NewRelic.AgentEnabled" value="true" />
<add key="NewRelic.AppName" value="DataServices" />
</appSettings>
But for ASP.NET Core, you don't use XML configuration, you use appsettings.json:
What are the configuration for ASP.NET Core?
Can the configuration be added to the Configuration of Azure Web App Service rather than in the local appsettings.json ? And if so, what are the keys?

In the doc page you provide, it is explained how to set it up in dotnet core.
You don't need to add anything to the appsettings file; just set an environment variable. Beware that it must be set only in the project's scope or all dotnet core applications running on the host will be monitored.
CORECLR_ENABLE_PROFILING=1
They provide a helpful link to a page with even more details: https://discuss.newrelic.com/t/setting-net-core-agent-environment-variables-per-process/157750
In addition to the methods they mention, you could also put the variable in a .env file and load it, for example as explained here https://dusted.codes/dotenv-in-dotnet

Related

Unable to run my .net core app in local as well as on server with IIS

I created a .net core api (version 2.2.0) and I'm getting the following error when I try to run on IIS.
The application process failed to start The application process
started but then stopped The application process started but failed to
listen on the configured port
I verified my web config and it appears to have correct set of values.Enabled logging and log file comes as empty.
Event log shows the following error.
I installed hosting bundle and checked still getting same error. Also tried giving permission to IIS_IUSRS to the output folder. It didn't make any difference. Having said that error code "'0x80004005' " suggests a permission error. Still couldn't figure it out. Appreciate any help !
Web config
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<location path="." inheritInChildApplications="false">
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath=".\MyApi.exe" stdoutLogEnabled="true" stdoutLogFile=".\logs\stdout" hostingModel="InProcess" />
</system.webServer>
</location>
</configuration>`enter code here`
<!--ProjectGuid: 4d7644bb-9348-46f9-8397-95f01e03d599-->
Make sure you publish the site properly in iis. Your site root folder has enough permission to access it by iis. assign the iis_iusrs and iusr permission to the site folder. your application pool identity is set application pool identity or local system. anonymous authentication is enabled. and you installed the iis asp.net feature. make sure your site binding is correct and the application pool is using correct .net version and running under integrated application pool.
The reason behind the error message
The HTTP Error 502.5 - Bad Gateway and HTTP Error 502.5 - Process
Failure error messages occur in ASP.NET Core when IIS fails to execute
the dotnet process.
.NET Core Runtime is not installed
web.config file has not been transformed
To resolve this issue you could refer one the below-suggested way:
Install the .NET Core Runtime
The most common reason for this to occur is when you haven't installed the .NET Core runtime on the server.
You can download the latest .NET Core runtime from Microsoft's .NET download page.
After installing Bundle stop iis and start again.
Publish a Self-Contained Deployment
If you don't want to install the .NET Core Runtime. An alternative for .NET Core web applications is to publish them in the Self-Contained deployment mode, which includes the required .NET Runtime files alongside your application.
If you go with this option, you'll also need to choose a target runtime: win-x86, win-x64, osx-x64, or linux-x64. Because self-contained deployments are not portable.
Transform your web.config file
Another reason for this error to occur is when you deploy an untransformed web.config file.
This is likely to be your issue if you had a previously working web application and merely deployed a new version of it.
In ASP.NET Core applications, the web.config file contains a handler that directs requests to the AspNetCoreModule and an aspNetCore element that defines and configures the ASP.NET Core process to execute your web application.
Here is a minimal web.config file for an ASP.NET Core application:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModule" resourceType="Unspecified" />
</handlers>
<aspNetCore processPath="%LAUNCHER_PATH%" arguments="%LAUNCHER_ARGS%" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false"/>
</system.webServer>
</configuration>
The issue is The untransformed web.config contains the variables %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct paths. When IIS tries to run ASP.NET Core, it uses %LAUNCHER_PATH% and %LAUNCHER_ARGS% rather than the correct path and arguments.
To fix the HTTP Error 502.5 in ASP.NET Core, you need to transform the web.config and replace the untransformed web.config file on the IIS web server.
steps to transform web.config file:
This transformation takes place when you choose to publish your web application. The transformed web.config ends up in the published output folder. Therefore, you simply need to publish your web application and copy the resulting web.config file onto the server.
In a transformed web.config file, the aspNetCore element will look something like this:
<aspNetCore processPath="dotnet" arguments=".\MyApplication.dll" stdoutLogEnabled="true"
stdoutLogFile=".\logs\stdout" forwardWindowsAuthToken="false" />
%LAUNCHER_PATH% has been replaced by dotnet and %LAUNCHER_ARGS% has been replaced by the path to the main web application dll .\MyApplication.dll.
links:
Publish an ASP.NET Core app to IIS

ASP.NET Core deploy only applicable appsettings.{EnvironmentName}.json

I've made my first proof of concept ASP.NET Core application, I have 5 appsettings files:
appsettings.json
appsettings.Development.json
appsettings.Test.json
appsettings.Staging.json
appsettings.Production.json
I'm running the app in IIS so I actually have web.config files so that I can set the ASPNETCORE_ENVIRONMENT environment variable on a per application basis:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<aspNetCore processPath="dotnet" >
<environmentVariables>
<environmentVariable name="ASPNETCORE_ENVIRONMENT" value="Development"></environmentVariable>
</environmentVariables>
</aspNetCore>
</system.webServer>
</configuration>
I have 4 web.config transforms so I can publish from Visual studio, and it will set the correct environment variable value for each environment.
When I publish to each environment though it publishes all the appsettings files. Is it possible to get it to publish on the root appsettings.json and the applicable environment specific one, but omit the others?
No, it's not possible. ASP.NET Core is not like ASP.NET. In ASP.NET, you literally published for the environment; if you wanted to switch to a different environment, you'd need to republish. ASP.NET Core is published for all environments. The same published app can be picked up and moved to any environment, without change. The actual environment is generally externalized, such as via and environment variable, and can be changed on a whim, without requiring new code to be deployed. This is actually a feature of ASP.NET Core.
Now, the way you're handling the environment variable does somewhat make it dependent on the publish, but that's just modifying the web.config, which itself only has meaning when deploying to IIS. ASP.NET Core itself doesn't care about or use web.config, and honestly doesn't even care about or use release configurations.

ELMAH for ASP .NET MVC Windows Application

I need to log errors for an asp.net mvc windows application which also uses entity framework and for doing this i thought of using ELMAH.
My App.config file contains the appsettings for providing folderpath and other file related details.
Now when I try to add the configuration (elmah...../elmah) for ELMAH after installing it in my project it throws an exception "Configuration system failed to initialize".
But when I remove that code then it works fine.
Please provide me the solution to log errors for MVC windows application.
And the final question is ELMAH.mvc free to use or not?
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="folderpath" value="~PA\FileImport"/
<add key="XMLFolderPath" value="~\FileImport\XML"/>
</appSettings>
<connectionStrings>
<add name="####" connectionString="############"
providerName="System.Data.EntityClient" />
</connectionStrings>
<elmah>
..........
</elmah>
</configuration>
It sounds like there's a problem with your ELMAH configuration, since ELMAH and EntityFramework normally doesn't interfere with each other. I would recommend you to follow a tutorial like this: ELMAH Tutorial. There's a ton of tutorials for ELMAH outthere, why a simple google search will find a lot of resources.
If following a tutorial doesn't work, you should probably add some additional information and web.config code in this thread, since figuring out your problem from the amount of information, is almost impossible.

IIS WCF Service not using app.config

I have a .NET 3.5 WCF service hosted in IIS. The project service library has an app.config file with some configuration settings (Database connection strings, etc.). I deploy the project via a website project in Visual Studio, which generates a web.config to manage the endpoints. Is there a way I can put the app.config settings from my service library in to the web.config? The IIS hosted service seems to be using default values from the settings designer, and ignoring even an expliclty copied in app.config. I'm guessing this has something to do with the fact that a DLL can not utliize an app.config.
My service application is set up to pull the settings settings from the [MyAssembly].Properties.Settings.Default namespace.
Can you use external configuration files?
Your web.config:
<config>
...
<connectionStrings configSource="myConnections.config"></connectionStrings>
</config>
And then your external myConnections.config file:
<connectionStrings>
<add ... />
</connectionStrings>
You can have multiple external configuration files referenced from your main web.config file. See see this blog post for a nice explanation of how/why to do this.
I hope this helps!

Why is this class library dll not getting information from app.config

I am developing a custom HttpHandler, to do so I write a C# Class Library and compile to DLL.
As part of this I have some directory locations which I want not hard coded in the app, so i'm trying to put it in the app.config which I've used before.
Before this has worked by just going building the app.config:
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<appSettings>
<add key="Share" value="C:\...\"/>
</appSettings>
</configuration>
And then obtaining this in code like:
var shareDirectory = ConfigurationManager.AppSettings["Share"];
But when I compile it and put it in the bin folder for the webservice, it keeps getting null for shareDirectory, probably because it can't find app.config. So how do I make sure this is included so I don't have to hard code my direcotry locations? I notice it will essentially after compiled we get the assembly.dll and the assembly.dll.config which is the app.config file, so it's definetly there in the bin folder!
That is because your web service uses web.config
You're probably confusing the scope of your class library.
Remember, your config, be it web.config, or app.config, is the config present in the HOSTING application. In this case your hosting application is the WebService, hosted of course by IIS, so your config file is the web.config.
If you had a console app which somehow used that class library (though probably not in an http handler context), then the config would be the app.config in the console app, not the app.config in your class library.
You need to put the configuration in your web.config file, not in assembly.dll.config: .NET does not (by design) read assembly.dll.config files.