I have a website as 'App Service' in Azure and 'Service Fabric' with a number of services for background tasks. For logging I want to use log4net and for analyzing AppInsights. Like:
WebSite --> log4net --> AppInsights appender --> AppInsights
Service Fabric --> log4net --> AppInsights appender --> AppInsights
The question is: what is the correct way to implement described logging flow, the idea is to log with log4net and analyze with AppInsights. And can I distinguish logs in AppInsights from website and service fabric.
The question is: what is the correct way to implement described logging flow, the idea is to log with log4net and analyze with AppInsights.
Per my understanding, you could follow the steps below for logging with log4net into application insights:
Add Application insights to your project,for more details, you could refer to Set up Application Insights for your ASP.NET website.
Install the Application Insights Log4Net Appender.
For add diagnostic log via log4Net:
logger.Info("Hello world!!!");
Here I created my asp.net MVC application, configured the application insights and installed the related package, then added the following configuration under the Application_Start
method from the Global.asax.cs
file as follows:
log4net.Config.XmlConfigurator.Configure();
Then, I deployed my web application to my two azure web apps, then I could search the log as follows:
And can I distinguish logs in AppInsights from website and service fabric.
You could leverage Analytics in Application Insights and write your query to distinguish the logs from different services based on your filters as follows:
Additionally, I would prefer creating a new application insights for each of my azure web apps, since there has 1GB(s) per month for free and it would be simple for me to manage my diagnostic logging.