示例#1
0
        // This method gets called by the runtime. Use this method to add services to the container.
        public void ConfigureServices(IServiceCollection services)
        {
            ICustomConfigurationSettings configSettings = Configuration.Get <CustomConfigurationSettings>();

            services.AddControllers();

            // Register the Swagger generator, defining 1 or more Swagger documents
            services.AddSwaggerGen();


            Log.Logger = new LoggerConfiguration()
                         .ReadFrom.Configuration(Configuration)
                         //.Enrich.FromLogContext()
                         .Enrich.WithProperty("Version", typeof(Program).Assembly.ImageRuntimeVersion)
                         .CreateLogger();

            try
            {
                throw new Exception("Trying to throw an error deliberately");
            }
            catch (Exception ex)
            {
                Log.Logger.Error(ex, "Trying to log my first error message on azure app insights");
            }

            Log.Logger.Information("Logging my first message from Serilog");

            services.AddSingleton(Log.Logger);
            services.AddSingleton(configSettings);
            services.AddTransient <IAzureSearchService, AzureSearchService>();
            //services.AddTransient<ICustomConfigurationSettings, CustomConfigurationSettings>();
            //services.AddApplicationInsightsTelemetry(Configuration["APPINSIGHTS_INSTRUMENTATIONKEY"]);
        }
示例#2
0
 public AzureSearchService(ICustomConfigurationSettings customConfigurationSettings, ILogger logger)
 {
     _CustomConfigurationSettings = customConfigurationSettings;
     _logger           = logger;
     searchServiceName = _CustomConfigurationSettings.AzureSearchName;
     adminKey          = _CustomConfigurationSettings.AzureSearchAdminKey;
     queryKey          = _CustomConfigurationSettings.AzureSearchQueryApiKey;
 }
 public AzureSearchDemoController(ILogger logger, IAzureSearchService azureSearchService, ICustomConfigurationSettings customConfigurationSettings)
 {
     _logger                      = logger;
     _azureSearchService          = azureSearchService;
     _CustomConfigurationSettings = customConfigurationSettings;
 }