Azure Smart Detection Нет данных - PullRequest
0 голосов
/ 10 июля 2020

Я хочу протестировать интеллектуальное обнаружение для моего ASP. NET CORE 3.1, но данные недоступны ...

Мое веб-приложение запущено с моего ноутбука, и я знаю, что Smart Машинному обучению обнаружению требуется 8+ дней, чтобы изучить обычные параметры моего приложения. Я также установил 2 учетные записи и дал одной из этих ролей: Monitoring Reader, Monitoring Contributor согласно заявлению в документации, что он будет автоматически отправлять уведомление при обнаружении ненормального поведения.

У меня есть журналы, доступные с 25 Июнь 2020 года, и приложение запускалось каждый день, так как я сейчас узнаю о AZURE ... но все еще нет данных:

Диапазон времени установлен с 1 ИЮНЯ 2020 до сегодняшнего дня 10 ИЮЛЯ 2020 SmartDetection

Log data available:

LogAnaliticsData

Live Metrics Data(I have configured a browser extension to make requests every 1 seconds to simulate an increase in requests and logging):

enter image description here

[Context]

ASP.Net Core 3.1 setup with Serilog, Azure Application Insights SINK, and ASP.NET CORE HTTPContext enricher.

[Serilog Config] 1.Program.cs Main method:

    var loggerConfiguration = new LoggerConfiguration()
                    .MinimumLevel.Override("Microsoft.AspNetCore", LogEventLevel.Warning)
                    .ReadFrom.Configuration(config);
    
                var telemetryConfiguration = TelemetryConfiguration
                    .CreateDefault();
        telemetryConfiguration.InstrumentationKey = "KeyHere";
     loggerConfiguration
                    .WriteTo
                    .ApplicationInsights(telemetryConfiguration, TelemetryConverter.Traces);
         loggerConfiguration
                    .WriteTo
                    .Console(
                    LogEventLevel.Information,
                    "{Timestamp:yyyy-MM-dd HH:mm:ss.fff} | {Level:u3} | {SourceContext} {Message:jl} | {Exception} | CorrelationId= {CorrelationId} |{NewLine}");
    
    
                Log.Logger = loggerConfiguration
                    .Enrich.FromLogContext()
                    .CreateLogger();
    
                try
                {
                    Log.Information("1. Starting the app {_function_} ", nameof(Main));
                    CreateHostBuilder(args).Build().Run();
                }
                catch (Exception ex)
                {
                    Log.Fatal(ex, "1. Stopping the app");
                }
                finally
                {
                    Log.Information("1. Stopping the app {_function_}", nameof(Main));
    
                    Log.CloseAndFlush();
                }
    
       public static IHostBuilder CreateHostBuilder(string[] args) =>
                Host.CreateDefaultBuilder(args)
                    .ConfigureWebHostDefaults(webBuilder =>
                    {
                        webBuilder.UseStartup();
                    })
                    .UseSerilog();
  1. Startup.cs COnfigureServices:

services.AddApplicationInsightsTelemetry («KeyHere»);

Настроить: app.UseSerilogRequestLogging ();

     app.UseSerilogLogContext(options =>
       {
           options.EnrichersForContextFactory = context =>
           {
               var requestPath= context.Request.Path;
               return new[]
               {
                   new PropertyEnricher("Xyz", requestPath),
               };
           };
       });

Пример контроллера:

  public class WeatherForecastController : ControllerBase
{
private readonly ILogger _logger;

        public WeatherForecastController(
            ILogger logger,
            IWeatherForecastService forecastService)
        {
            _forecastService = forecastService;
            _logger = logger.ForContext<WeatherForecastController>();

            _logger.Information("4.1 Instantiating the WeatherForecastController {_function_}", nameof(WeatherForecastController));
        }
[HttpGet]
        public IActionResult Get()
        {
            _logger.Information("4.2 Entering the GetMethod  {_function_}", nameof(Get));

            try
            {
                var rng = new Random();
                var temperature = rng.Next(-20, 55);
                _logger.Information("4.3 Display these values {randomValue} {temperature}", rng, temperature);

                var result = _forecastService.GetForecastAsync();

                if (temperature < 0)
                {
                    throw new NotImplementedException();
                }

                return Ok(result);
            }
            catch (Exception ex)
            {
                _logger.Error(ex, "4.4 This is for testing a random exception.");
                return StatusCode(500);
            }
}

СПАСИБО !!

...