public TelemetryHelper(bool disableTelemetry = false) { Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration configuration = Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration.CreateDefault(); configuration.InstrumentationKey = "60ab83db-108f-45ee-b537-d70dc47d3193"; configuration.DisableTelemetry = disableTelemetry; TC = new TelemetryClient(configuration); var assemblyVersion = this.GetType().Assembly.GetName().Version; Version = $"{assemblyVersion.Major}.{assemblyVersion.Minor}.{assemblyVersion.Build}"; }
private static void InitializeConfiguration() { var builder = new ConfigurationBuilder().AddJsonFile("appsettings.development.json", false, true); Configuration = builder.Build(); var appinsightKey = Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]; var config = new Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration(appinsightKey); telemetry = new Microsoft.ApplicationInsights.TelemetryClient(config); telemetry.TrackTrace("EPH configuration initialized...", SeverityLevel.Information); }
private static async Task Main(string[] args) { // Run with console or service var asService = !(Debugger.IsAttached || args.Contains("--console")); var builder = new HostBuilder() .ConfigureAppConfiguration((hostContext, config) => { config.SetBasePath(Directory.GetCurrentDirectory()); config.AddEnvironmentVariables(); }) .ConfigureLogging((context, logging) => { logging.AddConfiguration(context.Configuration); logging.AddSentry(); }) .ConfigureServices((hostContext, services) => { services.AddHostedService <WorkerService>(); WorkerService.ConfigurarDependencias(hostContext.Configuration, services); WorkerService.Configurar(hostContext.Configuration, services); services.AddApplicationInsightsTelemetryWorkerService(hostContext.Configuration.GetValue <string>("ApplicationInsights__InstrumentationKey")); var provider = services.BuildServiceProvider(); //services.AddSingleton<IConnectionMultiplexerSME>( // new ConnectionMultiplexerSME(hostContext.Configuration.GetConnectionString("SGP_Redis"), provider.GetService<IServicoLog>())); // Teste para injeção do client de telemetria em classe estática , var telemetryConfiguration = new Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration(hostContext.Configuration.GetValue <string>("ApplicationInsights:InstrumentationKey")); var telemetryClient = new TelemetryClient(telemetryConfiguration); DapperExtensionMethods.Init(telemetryClient); // services.AddMemoryCache(); }); builder.UseEnvironment(asService ? EnvironmentName.Production : EnvironmentName.Development); if (asService) { await builder.Build().RunAsync(); } else { await builder.RunConsoleAsync(); } }
static async Task RunAsFunction() { InitializeConfiguration(); //Event hub settings string EventHubName = Configuration["EventHubName"]; string EventHubConnectionString = Configuration["ConnectionStrings:TestEventHubConnection"]; //Storage settings string StorageContainerName = Configuration["StorageContainerName"]; string StorageConnectionString = Configuration["ConnectionStrings:AzureWebJobsStorage"]; string globalAppInsightsKey = String.Empty; var builder = new HostBuilder() .UseEnvironment("Development") .ConfigureWebJobs(b => { EventProcessorHost eventProcessorHost = new EventProcessorHost( EventHubName, PartitionReceiver.DefaultConsumerGroupName, EventHubConnectionString, StorageConnectionString, StorageContainerName); eventProcessorHost.PartitionManagerOptions = new PartitionManagerOptions() { LeaseDuration = new TimeSpan(0, 0, 15), RenewInterval = new TimeSpan(0, 0, 4) }; b.AddAzureStorageCoreServices(); b.AddEventHubs(a => a.AddEventProcessorHost(EventHubName, eventProcessorHost)); //b.AddAzureStorageCoreServices(); //b.AddEventHubs(); }) .ConfigureAppConfiguration(b => { b.AddJsonFile("appsettings.development.json"); }) .ConfigureLogging((context, b) => { b.SetMinimumLevel(LogLevel.Trace); b.AddAzureWebAppDiagnostics(); b.AddConsole(); string appInsightsKey = context.Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]; globalAppInsightsKey = appInsightsKey; // If this key exists in any config, use it to enable App Insights if (!string.IsNullOrEmpty(appInsightsKey)) { b.AddApplicationInsights(o => o.InstrumentationKey = appInsightsKey); } }) .UseConsoleLifetime(); var host = builder.Build(); using (host) { var options = host.Services.GetService <IOptions <EventHubOptions> >().Value; var assemblies = AppDomain.CurrentDomain.GetAssemblies(); var config = new Microsoft.ApplicationInsights.Extensibility.TelemetryConfiguration(globalAppInsightsKey); var telemetry = new Microsoft.ApplicationInsights.TelemetryClient(config); telemetry.TrackTrace("WebJob host initialized and starting..."); foreach (var item in assemblies) { telemetry.TrackTrace($"Loaded assembly: {item.FullName}", Microsoft.ApplicationInsights.DataContracts.SeverityLevel.Information); } await host.RunAsync(); await host.WaitForShutdownAsync(); } }