You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
88 lines
3.1 KiB
88 lines
3.1 KiB
using DealerSelection.Common.HttpClient;
|
|
using DealerSelection.Common.Interfaces.HttpClient;
|
|
using Lamar;
|
|
using Microsoft.ApplicationInsights.Extensibility;
|
|
using Microsoft.ApplicationInsights.WindowsServer.TelemetryChannel;
|
|
using Microsoft.AspNetCore.Builder;
|
|
using Microsoft.AspNetCore.Hosting;
|
|
using Microsoft.Extensions.Configuration;
|
|
using Microsoft.Extensions.DependencyInjection;
|
|
using Microsoft.Extensions.Hosting;
|
|
using Microsoft.Extensions.Logging;
|
|
using Microsoft.Extensions.Logging.ApplicationInsights;
|
|
|
|
namespace WebJobService;
|
|
|
|
|
|
public class Program : ServiceRegistry
|
|
{
|
|
|
|
static void Main()
|
|
{
|
|
var registry = new ServiceRegistry();
|
|
registry.AddSingleton<IHttpClientHandler, MyHttpClientHandler>();
|
|
registry.AddSingleton<IRepository, Repository>();
|
|
|
|
var builder = new ConfigurationBuilder().AddJsonFile($"appsettings.json", true, true);
|
|
var config = builder.Build();
|
|
var aiUrl = config["AZURE_LOGGING"];
|
|
|
|
registry.AddLogging(x => x.AddApplicationInsights(
|
|
configureTelemetryConfiguration: (config) => config.ConnectionString =
|
|
aiUrl, configureApplicationInsightsLoggerOptions: (options) => { }
|
|
).AddFilter<ApplicationInsightsLoggerProvider>("traces", LogLevel.Trace));
|
|
|
|
|
|
|
|
registry.For<IRepository>()
|
|
.Use<Repository>()
|
|
.Ctor<string>().Is("BOOKING")
|
|
.Transient();
|
|
|
|
registry.For<IService>().Use<Service>().Singleton();
|
|
|
|
//IServiceCollection services1 = new ServiceCollection();
|
|
//var CHANNEL1 = new ServerTelemetryChannel();
|
|
//services1.Configure<TelemetryConfiguration>((config) =>
|
|
//{
|
|
// config.TelemetryChannel = CHANNEL1;
|
|
//});
|
|
|
|
//services1.AddLogging(builder => { builder.AddApplicationInsights(aiUrl); });
|
|
//var provider=services1.BuildServiceProvider();
|
|
|
|
//var logger=provider.GetService<ILogger<Program>>();
|
|
//logger.LogInformation("Its a Test");
|
|
|
|
//Host.CreateDefaultBuilder(args)
|
|
// .ConfigureWebHostDefaults(webBuilder =>
|
|
// {
|
|
// webBuilder.UseStartup();
|
|
// })
|
|
// .UseSerilog((hostingContext, loggerConfiguration) => loggerConfiguration
|
|
// .ReadFrom.Configuration(hostingContext.Configuration)
|
|
// .WriteTo.ApplicationInsights(new TelemetryConfiguration { InstrumentationKey = "xxxxxxxxx" }, TelemetryConverter.Traces)
|
|
// );
|
|
|
|
var container = new Container(registry);
|
|
|
|
|
|
IService service = container.GetInstance<IService>();
|
|
service.Run();
|
|
// Handling finalizing when process is ended
|
|
|
|
|
|
}
|
|
|
|
private void AzureLogging(WebApplicationBuilder builder)
|
|
{
|
|
builder.Logging.AddApplicationInsights(
|
|
configureTelemetryConfiguration: (config) => config.ConnectionString =
|
|
builder.Configuration.GetConnectionString("AZURE_LOGGING"),
|
|
configureApplicationInsightsLoggerOptions: (options) => { }
|
|
);
|
|
builder.Logging.AddFilter<ApplicationInsightsLoggerProvider>("traces", LogLevel.Trace);
|
|
}
|
|
|
|
|
|
}
|