Disable lifetime application logging from a BackgroundService in .NET 7 - backgroundworker

I want to remove messages such as "Application started. Hosting environment: Production; Content root path: ..." or "Application is shutting down" from my .NET 7 windows service.
I tried to mess with the Logging json object in the appsetting.json file to disable logs from Microsoft but it didn't work... I also tried to add builder.ClearProviders() and builder.UseConsoleLifetime(x => x.SuppressStatusMessages = true) but I get an error 1053 when starting the service.
Is there a solution to not print out these messages?

Related

Strange behavior when trying to connect to Azure App Configuration with .Net Framework

I have encountered a strange behavior when trying to connect to Azure App Configuration with an Azure Identity from an ASP.Net Web Application. Current environment is .Net Framework 4.8, but the behavior is the same on 4.7.2 and 4.6.1.
I am using Microsoft.Extensions.Configuration.AzureAppConfiguration 4.0.0 and Azure.Identity 1.3.0. During local development I am using a service principal (AZURE_TENANT_ID, AZURE_CLIENT_ID and AZURE_CLIENT_SECRET defined in environment) and on Azure the system assigned ManagedIdentity of the app service.
private IConfiguration GetConfiguration(string label = null)
{
TokenCredential credential = new DefaultAzureCredential();
return new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.AddAzureAppConfiguration(options =>
{
options = options.Connect(
new Uri(Environment.GetEnvironmentVariable("APP_CONFIGURATION_ENDPOINT")), credential)
.ConfigureKeyVault(kv => { kv.SetCredential(credential); });
if (!string.IsNullOrEmpty(label))
{
options.Select(KeyFilter.Any, label);
}
else
{
options.Select(KeyFilter.Any, LabelFilter.Null);
}
})
.Build();
}
This code snippet works, when executed during application startup, e.g. RouteConfig. All subsequent calls are working, also refresh does work without problems.
The problems are starting when first calling App Configuration at a later time, e.g. during a request. The code hangs without an error message. In my special situation I am not able to connect to Azure App Configuration at startup time.
When using .Net Core, everything works like a charm but currently this is not an option.
Here are the logs.
When executed during startup:
Starting IIS Express ...
Successfully registered URL "http://localhost:5000/" for site "AppConfigTest3" application "/"
Registration completed for site "AppConfigTest3"
IIS Express is running.
Enter 'Q' to stop IIS Express
Loading configuration ...
Created DefaultAzureCredential: Azure.Identity.DefaultAzureCredential
Using Azure environment
Created ManagedIdentityCredential: Azure.Identity.DefaultAzureCredential
Connected via APP_CONFIGURATION_ENDPOINT: https://my-test-appconfig.azconfig.io
Before configure KeyVault credential
After configure KeyVault credential
Before executing Build()
EscalationMonitorInterval: 300
Created DefaultAzureCredential: Azure.Identity.DefaultAzureCredential
Using Azure environment
Created ManagedIdentityCredential: Azure.Identity.DefaultAzureCredential
Connected via APP_CONFIGURATION_ENDPOINT: https://my-test-appconfig.azconfig.io
Before configure KeyVault credential
After configure KeyVault credential
Before executing Build()
Azure Config loaded
Anforderung gestartet: "GET" http://localhost:5000/
If called the first time during a request, I'm getting the following log:
Starting IIS Express ...
Successfully registered URL "http://localhost:5000/" for site "AppConfigTest3" application "/"
Registration completed for site "AppConfigTest3"
IIS Express is running.
Enter 'Q' to stop IIS Express
Azure Config loaded
Anforderung gestartet: "GET" http://localhost:5000/
Response sent: http://localhost:5000/ with HTTP status 200.0
Anforderung gestartet: "GET" http://localhost:5000/Home/About
Loading configuration ...
Created DefaultAzureCredential: Azure.Identity.DefaultAzureCredential
Using Azure environment
Created ManagedIdentityCredential: Azure.Identity.DefaultAzureCredential
Connected via APP_CONFIGURATION_ENDPOINT: https://my-test-appconfig.azconfig.io
Before configure KeyVault credential
After configure KeyVault credential
Before executing Build()
Nothing happens and the request does not return.
I'm stucked at this point. Does someone has a solution for this problem? Thank you.
Regards,
Stati
This is because of a bug introduced in Azure.Core package version 1.4.1. The bug has been fixed in Azure.Core version 1.9.0. Since you are referencing Azure.Identity version 1.3.0, you have an indirect dependency on Azure.Core version 1.6.0.
Your problem can be fixed by adding an explicit dependency on Azure.Core v1.9.0 or later.

Integration of Tomcat 7 with IIS 7

After following all the steps related to integration of tomcat7 and IIS7 i am getting below error.Any idea what might be the cause?First time when I did all the steps as mentioned in tutorial my site was coming up then suddenly it stop coming up.Again i removed my site from IIS and followed the steps but then every time below error is coming:-
HTTP Error 500.0 - Internal Server Error
The page cannot be displayed because an internal server error has occurred. Detailed Error Information
Module IsapiFilterModule
Notification AuthenticateRequest
Handler StaticFile
Error Code 0x80070001
Physical Path D:\New\IISROOT
Logon Method Anonymous
Logon User Anonymous
Failed Request Tracing Log Directory D:\New\Tomcat\logs
I have checked the logs but trace log is not created as well as isapi_redirect.logs
I have followed the below steps:
1.created the two files workers.properties and uriworkermap.properties in tomcat\conf
-In workers.properties i added the below information
worker.list=mysite worker.mysite.host=localhost worker.mysite.port=8009 worker.mysite.type=ajp13
-In uriworkermap.properties i added the below information
/mysite/*=mysiteworker
2.Created isapi-rediect.properties in Tomcat\bin
extension_uri=/jakarta/isapi_redirect.dll log_file=D:\DLNew\Tomcat\logs\isapi_redirect.log log_level=debug worker_file=C:\Tomcat\conf\workers.properties worker_mount_file=c:\Tomcat\conf\uriworkermap.properties
3.Add ISAPI Filter
In AddIsapi Filter dialog box i have given filtername as jakarta and Executable path as c:\Tomcat\bin\isapi\isapi-redirect.dll
2.Add Virtual Directory
In Add VirtualDirectory Dialog box i have given Alias as jakarta and PhysicalPath as c:\Tomcat\bin\isapi
3.selected jakarta virtual directory in connections panel -Double-click the 'Handler Mappings' icon in 'Features View'. -Click the 'Edit Feature Permissions' link in the 'Actions' panel. -Ensure that the 'Execute' option is selected.
4.Register the ISAPI Extension In ISAPI OR CGI restriction Dialog box i have given ISAPI or CGI path as c:\Tomcat\bin\isapi\isapi-redirect.dll and description as jakarta and i enabled the checkbox of allow extension path to execute
I am able to access the application through Tomcat by using the url as:http://localhost:80/mysite
But application is not comming up through IIS: i am getting below exception in browser
HTTP Error 500.0 - Internal Server Error The page cannot be displayed because an internal server error has occurred. Detailed Error Information Module IsapiFilterModule Notification AuthenticateRequest Handler StaticFile Error Code 0x80070001 Physical Path D:\New\IISROOT Logon Method Anonymous Logon User Anonymous Failed Request Tracing Log Directory c:Tomcat\logs

Umbraco 5 setup. Access to the path is denied

I use Windows Server 2008 R2, IIS 7.0.
I downloaded umbraco5 sources, created new site in IIS, set physical path to path to umbraco sources, edited permissions for IIS_IUSRS and NETWORK SERVICE. Then I installed umbraco, set admin's login and password. After it I added sources to new MVC3 project in VS2010 and set up web properties of the project to use IIS server (http://localhost:5050).
When I try to run project I get error: "Access to the path 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\57060572\e5101f9c\Umbraco.Cms.Web.Editors.dll' is denied."
I checked event viewer log, so here it is:
Event code: 4011
Event message: An unhandled access exception has occurred.
Event time: 20.03.2012 13:05:33
Event time (UTC): 20.03.2012 9:05:33
Event ID: f21a6458d0844eb08296e8e1e0c7d351
Event sequence: 1
Event occurrence: 1
Event detail code: 0
Application information:
Application domain: /LM/W3SVC/6/ROOT-9-129767079319772708
Trust level: Full
Application Virtual Path: /
Application Path: D:\asitnikov\tfs\HospitalSite\Sources\HospitalSite\HospitalSite\
Machine name: PC4
Process information:
Process ID: 5752
Process name: w3wp.exe
Account name: IIS APPPOOL\HospitalSite
Request information:
Request URL: http://localhost:5050/
Request path: /
User host address: ::1
User:
Is authenticated: False
Authentication Type:
Thread account name: IIS APPPOOL\HospitalSite
I've edited permissions for 'C:\Windows\Microsoft.NET\Framework64\v4.0.30319' folder and given full control to IIS_IUSRS, NETWORK SERVICE and IIS APPPOOL\HospitalSite but I see no effect.
Also, I have two logical disks on pc and when I make all these operations on disk "C" I don't run into this problem but only locating of project on disk "D" causes a trouble.
EDIT:
I've found out that location of my project (on disk "C" or on disk "D") makes no difference.
This sounds like a permissions problem. Did you install IIS after installing .NET framework 4?
You could try running The 'aspnet_regiis -ir' command to re-install the framework, which should also reset file permissions for these folders.
Ok, I solved this problem, just create a new project with different name following the instructions:
http://slickjuanito.wordpress.com/2012/02/27/setting-up-umbraco-development-environment-in-visual-studio-2010/

Classic asp "An error occurred when verifying security for the message." iis7 transport level security

On II7 we host a WCF/asp.net based API. In order to allow users of a classic asp application to connect to the API we had to publish a version we refer to as "transport". This Transport version is written in asp.net too, it points to the same assembly , its just the security layer is different to allow classic asp to authenticate. Transport level security is used as opposed to message based security.
When using a browser to load the service reference i can loading the svcutil.exe ... WDSL page.
When using my test asp page to call a web method from this reference i get the following returned:
Finished calling Web Service.
Status = Internal Server Error
ResponseText = a:InvalidSecurityAn error occurred when verifying security for the message.
This suggests that the authentication is failing. When testing using asp.net or the application WCF storm to contact the normal API everything works well.
The API was recently migrated , it would appear something has not been setup correctly but i am at a loss to explain what.
I can browse to the svcutil.exe ... WDSL service reference, when selecting it via the browser i get the expect XML response.
The USER NAME and password utilised work when using the non-classic asp publicaiton of the API using the message based secuirty.
Would it be possible to post some troubleshooting tip that may help diagnoise the issue please specifically regarding transport level security fault finding and setup ?
Thank you
Scott
EDITED TO ADD THE FOLLOWING UPDATE:
Attempted to use the Default App Pool and a new App Pool but same problem persists.
My test page error: ResponseText = a:InvalidSecurityAn error occurred when verifying security for the message.
IIS LOG shows:
v3/transport/testclassicasptransportwcfservice.asp ( 200 0 0 ) (i.e iis 200)
/V3/Transport/DeviceService.svc/DeviceService (500 0 0) (i.e iis error 500)
note: virtual dir defined on TRANSPORT and V3. V3 works ok using .net as opposed to classic asp to authenticate.
EVENT LOG:
The Template Persistent Cache initialization failed for Application Pool 'transport' because of the following error: Could not create a Disk Cache Sub-directory for the Application Pool. The data may have additional error codes.
This reference appears to suggest a fix but many of the DIR paths and references in "appcmd" dont exist.
_http://theether.net/kb/100127
REF http://theether.net/kb/100127
load cmd prompt
CD to C:\Windows\System32\inetsrv
enter: appcmd list config -section:system.webServer/asp
the following path is displayed: c:\inetpub\conf\temp\ASP compiled templates
check path exists (it does)
Check if the NETWORK SERVICE has permissions to access "ASP compiled templates" If not from appcmd execute;
icacls "c:\inetpub\conf\temp\ASP Compiled Templates" /grant "NETWORK SERVICE:(OI)(CI)(M)"
should read "sucessfully processed 1 files"
restarted app pool.
THE "InvalidSecurityAn error occurred when verifying security for the message" problem still persists but the "COULD NOT CREATE A DISK CACHE SUB-DIRECORY .... " error from the eventlog is no longer occurring.
Sorry another update. The network service permission change DID NOT resolve the issue , changeing to the DEFAULT APP POOL solved the problem.
Got a lead at last. Examined:
ServiceSecurityAudit set in service behaviour. Ref http://intrepiddeveloper.wordpress.com/2008/08/07/security-event-logging-auditing/#
IIS logs (simply shows the non-specific error 500.)
Fault tracing enabled( also shows error 500).
Custom errors were off
Friendly IE messages were off
Asp client side and server side debugging on
ProcessMon running , no errors.
Web.config httpErrors errorMode="Detailed" /> +
ServiceSecurityAudit found me an "Object reference not set to an instance of an object" so sounds like our app has a bug.
Follow up (17/08/11):
Service Security Audit documented here:
http://intrepiddeveloper.wordpress.com/2008/08/07/security-event-logging-auditing/
Was the key for us to resolve this issue. Uncovered the Object Reference Error which indicated out Business Objects and Data Access dlls were out of alignment. Using CLASSIC ASP to contact the WCF.NET API using TRANSPORT AUTHENTICATION there was abolutely no indication of this error until Service Security Audit was enavled on the behaviour.config file in the WCF deployment.

changing aspnet user to the domain user to access iis

I'm running IIS5.0 and I am trying to change the ASP.NET process account to my domain user account.
I have followed everything possible here.
When I browse the .svc file (this is a wcf service) I am getting this error:
Server Application Unavailable The
web application you are attempting to
access on this web server is currently
unavailable. Please hit the "Refresh"
button in your web browser to retry
your request.
Administrator Note: An error message
detailing the cause of this specific
request failure can be found in the
application event log of the web
server. Please review this log entry
to discover what caused this error to
occur.
Eventlog says:
aspnet_wp.exe could not be started.
The error code for the failure is
80070522. This error can be caused when the worker process account has
insufficient rights to read the .NET
Framework files. Please ensure that
the .NET Framework is correctly
installed and that the ACLs on the
installation directory allow access to
the configured account.
When I run the client, I get the following error:
The content type text/html;
charset=utf-8 of the response message
does not match the content type of the
binding (application/soap+xml;
charset=utf-8). If using a custom
encoder, be sure that the
IsContentTypeSupported method is
implemented properly. The first 872
bytes of the response were: '
From ASP.NET 2.0 onwards, the correct method to ensure that a user account has the correct rights to run as the worker process identity is to run this command:
aspnet_regiis -ga [account]
You need to run the aspnet_regiis command that matches the ASP.NET version you plan on running:
ASP.NET 2.0 -
%SYSTEMROOT%\Microsoft.NET\Framework\v2.0.50727\aspnet_regiis.exe -ga [account]
ASP.NET 4.0 -
%SYSTEMROOT%\Microsoft.NET\Framework\v4.0.30319\aspnet_regiis.exe -ga [account]
If you put your Domain Account under IIS_WPG group, it should ideally work. If it doesn't work, there is a sure shot way of fixing it.
In IIS 6... step 1 is applicable... since you are on IIS 5, ignore step 1
Run it with Local System to begin with. If the applications runs, it means your IIS is configured well and you can proceed with the step 2.
Change the account to your domain account, and ensure that you have put the account in IIS_WPG as well. After that, run the tool called Process Monitor http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx
Browse the application now. If you still get the error, switch to the Process Monitor and stop capture [menu option].
Search for Access denied and fix it. Link

Resources