I have an Azure App for a .net core API, which in turn has a Sub Application (Virtual Directory). I have enabled Application log in the Diagnostic setting in the Azure Portal. I had done this for a another service and worked fine. When I have the services with multiple Virtual Directory setup it fails. Do we need any extra code in the Configure section if we have this scenario?
I can't reproduce the issue you mentioned. It works well to get Application logs. I also created a Virtual Directory in App Service. (refer to this article). And we needn’t to add extra code. You could follow my steps.
In Azure portal>APP Service>Application settings(create virtual directory ‘janley’):
Code in application: (Add the trace info).
public ActionResult Index()
{
Trace.TraceInformation("my trace info Home/Index");
return View();
}
public ActionResult About()
{
Trace.TraceInformation("my trace info Home/About");
return View();
}
public ActionResult Contact()
{
Trace.TraceInformation("my trace info Home/Contact");
return View();
}
You could see the logs in KuDu like this:
Besides, for more details about how to trace and view the application logs, you could read this article.
Changing the app from .net core to .net framework worked for me!
Related
I have setup an App and deploying using Azure. If I deploy and connect to the Azure SignalR then it is fine, and I can manage with the Azure message limits etc. However, when I try to use the "default" SignalR from my project instead of the Azure service, the release configuration still tries to connect to the Azure one.
In my startup.cs, I am especially trying to NOT use the Azure SignalR.
services.AddSignalR();
and I have commented out this line that pointed to the Azure one:
services.AddSignalR().AddAzureSignalR("Endpoint=https://<myApp>.service.signalr.net;AccessKey=<MyKey>;Version=1.0;");
Now when I publish as a Release configuration, Azure online is trying to connect to this host:
service.signalr.net
Whilst if I publish as a Debug configuration, Azure online is connecting to the host I want:
.azurewebsites.net
Which is the one I want for now.
Am tryuing to find out which varialbe is "forcing" Azure to use his own Service.SignalR.net in release mode. Could it be some of the variable I can see on the Azure App below? or is it a setting I need to put in the Visual Studio Code?
Thx.
I believe that what you can do is something like define the env on startup to use one or another but I can't say what will be the behaviour when you will set your variables on azure.
You should try something like:
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
if (env.IsDevelopment())
{
app.UseSignalR(routes =>
{
routes.MapHub<YourHub>("/YourHub");
});
}
else
{
app.UseAzureSignalR(routes =>
{
routes.MapHub<YourHub>("/YourHub");
});
}
}
I have a .Net core application that is deployed on service fabric Linux cluster. Application insights are configured in the app.
Startup.cs
public void ConfigureServices(IServiceCollection services)
{
ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions aiOptions
= new ApplicationInsights.AspNetCore.Extensions.ApplicationInsightsServiceOptions
{
EnableAdaptiveSampling = false,
EnableQuickPulseMetricStream = false,
InstrumentationKey = "xxx"
};
services.AddApplicationInsightsTelemetry(aiOptions);
I have a controller class that has some action methods and logs the information.
[HttpPost]
public ActionResult actionMethod(...)
{
TraceLine("------------------------------------");
//some code
}
private static void TraceLine(string msg)
{
msg = $">> {DateTime.UtcNow.ToString("o")}: {msg}";
Log.Information(msg);
}
I am using Serilog, configured in appsettings.json & Program.cs
When I hit action method directly from local (without hosting it on even local sf cluster), via Postman, I see app insights getting generated and pushed to azure.
azure app insights snapshot
But when I hit the action method that is deployed on Azure service fabric I don't see any insight getting generated.
What am I missing here?
Any help is much appreciated!
Well, we need to check a few things here:
1) The app insights URL and the instrumentation key in the deployment parameter files for cluster hosted on cloud (Cloud.xml)
2) After checking the Cloud.xml, the best way is to access the log files and check what is the actual problem.
There's a description here which explains how to discover where the log files are stored.
You can use RDP to access the machine, which is explained here.
I was able to solve the issue by using Microsoft.ApplicationInsights.ServiceFabric.Native SDK in my application to log app insights.
Refer .NetCore section in ApplicationInsights-ServiceFabric on how to configure insights for service fabric application.
Using .NET Core 2 in Azure App Service. Don't see my logs. In the actual application, the logging code looks like this:
using System.Diagnostics;
...
Trace.WriteLine("Logging works");
I expected to see the Trace logs in the Log Stream, but I don't. I do see general API logs. What am I doing wrong? My config below:
I had the same issue for .NET core azure web app: Trace.WriteLine method does not work(not write message to Application logs) for .NET core, but work for .NET framework , and I find the issue about that.
As a workaround for .NET core web application, I suggest you can use ILogger, which can write message to Application Logs.
In Startup.cs -> Configure method, re-write Configure method like below:
public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory)
{
//your other code
//add the following 2 lines of code.
loggerFactory.AddConsole();
loggerFactory.AddDebug();
app.UseStaticFiles();
//your other code
}
Then in HomeController.cs, add the following code:
public class HomeController : Controller
{
private readonly ILogger _logger;
public HomeController(ILoggerFactory loggerFactory)
{
_logger = loggerFactory.CreateLogger<HomeController>();
}
public IActionResult Index()
{
_logger.LogInformation("this is a information from ILogger...");
return View();
}
//other code
}
After publish to azure, and configure the Application Logging -> run the azure web app -> you can see the message is displayed in Application Logs:
I am trying to find out what the problem is with my application but I always get the following error page:
I tried adding to azure the ASPNETCORE_ENVIRONMENT variable, and then restarted, but it still does not work. Am I missing smth?
I tested at my side, and the app environment was changed to development:
Then, for testing, I just throw a Exception in my code, and I will see the detailed error page:
So, I have some suggestions:
1. Check if you have saved the application settings on Azure portal. And restart the web app.
2. You can force to use development environment in startup.cs
public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
{
//if (env.IsDevelopment())
//{
// app.UseDeveloperExceptionPage();
//}
// Force to use development environment
app.UseDeveloperExceptionPage();
...
}
And then re-publish it to you web app.
3. You can use remote debugging. Here is a tutorial: Troubleshoot an app in Azure App Service using Visual Studio
I have a dotnet core 1.1 web-api which uses ILogger to log to console. These logs are picked up and sent to blobs based on (appname)/month/day/hour if I turn on Application Logging (Blob) option under Monitoring/Diagnostic Logs in the azure console. This works out pretty well.
However, my webjob which uses the same ILogger and the same config does not have its output go to these mm/dd/hh directories.
If I turn on Application Logging (Filesystem) I see my logs, but I would really like them to go to the same blob storage location, so I can pick them up in Splunk.
Where am I going wrong?
According to your description, I created my console application with the target framework .NET Core 1.1 via VS2017 as follows:
Nuget packages:
Program.cs
class Program
{
static void Main(string[] args)
{
ILoggerFactory loggerFactory = new LoggerFactory()
.AddConsole()
.AddDebug()
.AddAzureWebAppDiagnostics();
ILogger<Program> logger = loggerFactory.CreateLogger<Program>();
logger.LogInformation("Hello World!");
logger.LogInformation("Sleeping for 5s before exit...");
Thread.Sleep(5 * 1000);
}
}
After deployed to azure, I could see the logs under KUDU console and the blob log file as follows: