From 2acd4930b1176b9b3634d2a7132ab06bfd642453 Mon Sep 17 00:00:00 2001 From: Wilco Krikke Date: Sat, 6 Feb 2021 14:06:49 +0100 Subject: [PATCH 1/8] Spray must now contain all fungicide properties --- FarmMapsBlight/BlightService.cs | 7 +++- FarmMapsBlight/FarmMapsBlight.csproj | 2 +- FarmMapsBlight/Models/Fungicide.cs | 48 ++++++++++++++++++++++++++++ FarmMapsBlight/Models/Spray.cs | 4 +-- 4 files changed, 57 insertions(+), 4 deletions(-) create mode 100644 FarmMapsBlight/Models/Fungicide.cs diff --git a/FarmMapsBlight/BlightService.cs b/FarmMapsBlight/BlightService.cs index fb050fb..1418ae6 100644 --- a/FarmMapsBlight/BlightService.cs +++ b/FarmMapsBlight/BlightService.cs @@ -36,8 +36,13 @@ namespace FarmMapsBlight taskRequest.attributes["plantingDate"] = plantingDate.ToUniversalTime().ToString("o"); taskRequest.attributes["emergeDate"] = emergeDate.ToUniversalTime().ToString("o"); + var fungicide1 = "{\"ai1\": \"propamocarb\", \"ai2\": \"fluopicolide\", \"ai3\": \"cymoxanil\", \"code\": \"infinito12curz\", \"name\": \"infinito 1,2 l + curzate partner 0,2 kg\", \"maxdose\": \"1\", \"mindose\": \"1\", \"safedays\": \"14\", \"emergence\": true, \"newgrowth\": \"1\", \"contentai1\": \"525.2\", \"contentai2\": \"62.5\", \"contentai3\": \"600\", \"fastgrowth\": true, \"contentunit\": \"l/ha + kg/ha\", \"rainfastness\": \"2.5\", \"tuberfilling\": true, \"aidescription\": \"(propamocarb + fluopicolide) 1.2 l/ha + cymoxanil 0.2 kg/ha\", \"curativescore\": \"2\", \"dryingtimemax\": \"2\", \"dryingtimemin\": \"2\", \"vracompatible\": false, \"maxapplications\": \"4\", \"preventivescore\": \"3\", \"recommendeddose\": \"1\", \"tuberprotection\": \"3.3\", \"eradicativescore\": \"2\", \"earlytubersetting\": true, \"protectioncategory\": \"2\", \"applicationrateunit\": null, \"ctgbregistrationnumber\": \"12927 n + 12755 n\"}"; + var fungicide2 = "{\"ai1\": \"fluazinam\", \"ai2\": \"cymoxanil\", \"ai3\": null, \"code\": \"kunshi\", \"name\": \"kunshi\", \"maxdose\": \"0.5\", \"mindose\": \"0.4\", \"safedays\": \"1\", \"emergence\": false, \"newgrowth\": \"1\", \"contentai1\": \"375\", \"contentai2\": \"250\", \"contentai3\": \"0\", \"fastgrowth\": true, \"contentunit\": \"g/kg\", \"rainfastness\": \"2.5\", \"tuberfilling\": false, \"aidescription\": \"(fluazinam + cymoxanil) 0.5 kg/ha\", \"curativescore\": \"2\", \"dryingtimemax\": \"2\", \"dryingtimemin\": \"1\", \"vracompatible\": true, \"maxapplications\": \"5\", \"preventivescore\": \"2.9\", \"recommendeddose\": \"0.5\", \"tuberprotection\": \"3.3\", \"eradicativescore\": \"1\", \"earlytubersetting\": false, \"protectioncategory\": \"1\", \"applicationrateunit\": \"kg/ha\", \"ctgbregistrationnumber\": \"14371 n\"}"; + List sprays = new List(); - sprays.Add(new Spray() { fungicideCode = "FLEX", SprayTime = new DateTime(2020, 9, 1), dose = 0.6, isVRA = false }); + sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide1), sprayTime = new DateTime(2020, 9, 1), dose = 0.6, isVRA = false }); + sprays.Add(new Spray() { fungicide = JsonConvert.DeserializeObject(fungicide2), sprayTime = new DateTime(2020, 9, 1), dose = 0.6, isVRA = false }); + taskRequest.attributes["sprays"] = JsonConvert.SerializeObject(sprays); List irrigations = new List(); diff --git a/FarmMapsBlight/FarmMapsBlight.csproj b/FarmMapsBlight/FarmMapsBlight.csproj index 052b891..dc870a8 100644 --- a/FarmMapsBlight/FarmMapsBlight.csproj +++ b/FarmMapsBlight/FarmMapsBlight.csproj @@ -11,7 +11,7 @@ - Never + PreserveNewest diff --git a/FarmMapsBlight/Models/Fungicide.cs b/FarmMapsBlight/Models/Fungicide.cs new file mode 100644 index 0000000..a8076c1 --- /dev/null +++ b/FarmMapsBlight/Models/Fungicide.cs @@ -0,0 +1,48 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace FarmMapsBlight.Models +{ + public class Fungicide + { + public string code { get; set; } + public string name { get; set; } + public string ctgbregistrationnumber { get; set; } + public string ai1 { get; set; } + public string ai2 { get; set; } + public string ai3 { get; set; } + public double contentai1 { get; set; } + public double contentai2 { get; set; } + public double contentai3 { get; set; } + public string contentunit { get; set; } + public string aidescription { get; set; } + public int protectioncategory { get; set; } + public double preventivescore { get; set; } + public double curativescore { get; set; } + public string applicationrateunit { get; set; } + public double recommendeddose { get; set; } + public double newgrowth { get; set; } + public double tuberprotection { get; set; } + public double dryingtimemin { get; set; } + public double dryingtimemax { get; set; } + public double rainfastness { get; set; } + public double mindose { get; set; } + public double maxdose { get; set; } + public int? maxapplications { get; set; } + public bool vracompatible { get; set; } + public double eradicativescore { get; set; } + public bool emergence { get; set; } + public bool fastgrowth { get; set; } + public bool earlytubersetting { get; set; } + public bool tuberfilling { get; set; } + public int? safedays { get; set; } + public double takeback + { + get + { + return curativescore * 6; + } + } + } +} diff --git a/FarmMapsBlight/Models/Spray.cs b/FarmMapsBlight/Models/Spray.cs index f0d2f29..2bccac9 100644 --- a/FarmMapsBlight/Models/Spray.cs +++ b/FarmMapsBlight/Models/Spray.cs @@ -4,8 +4,8 @@ namespace FarmMapsBlight.Models { public class Spray { - public DateTime SprayTime { get; set; } - public string fungicideCode { get; set; } + public DateTime sprayTime { get; set; } + public Fungicide fungicide { get; set; } public double dose { get; set; } public bool isVRA { get; set; } } From 1c04dfe1af06f1b2cd1f355688c95555e4f4446e Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Thu, 11 Feb 2021 14:51:27 +0100 Subject: [PATCH 2/8] fixed geotiftoshape to work with new taskmap task. --- FarmmapsApi/Services/GeneralService.cs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index e553174..36e5452 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -43,7 +43,7 @@ namespace FarmmapsApi.Services public async Task UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) { - var startUpload = DateTime.UtcNow; + var startUpload = DateTime.UtcNow.AddSeconds(-3); var result = await _farmmapsApiService.UploadFile(filePath, root.Code, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); @@ -82,6 +82,9 @@ namespace FarmmapsApi.Services public async Task GeotiffToShape(Item tiffItem) { var taskmapRequest = new TaskRequest {TaskType = TASKMAP_TASK}; + taskmapRequest.attributes["cellWidth"] = "3"; + taskmapRequest.attributes["cellHeight"] = "1"; + taskmapRequest.attributes["angle"] = "0"; string itemTaskCode = await _farmmapsApiService.QueueTaskAsync(tiffItem.Code, taskmapRequest); @@ -102,7 +105,7 @@ namespace FarmmapsApi.Services //the taskmap is a child of the input tiff var itemName = "Taskmap"; - var taskMapItem = await FindChildItemAsync(tiffItem.Code, + var taskMapItem = await FindChildItemAsync(tiffItem.ParentCode, SHAPE_PROCESSED_ITEMTYPE, itemName); if (taskMapItem == null) { From ee70322ddf754d3584ac382eadb2c44e5a992c44 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 15 Feb 2021 10:17:04 +0100 Subject: [PATCH 3/8] get correct item name for zonering --- FarmmapsZonering/FarmmapsZonering.csproj | 4 ---- FarmmapsZonering/Services/ZoneringService.cs | 5 ++--- 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/FarmmapsZonering/FarmmapsZonering.csproj b/FarmmapsZonering/FarmmapsZonering.csproj index dcc6344..6f9fc2a 100644 --- a/FarmmapsZonering/FarmmapsZonering.csproj +++ b/FarmmapsZonering/FarmmapsZonering.csproj @@ -21,8 +21,4 @@ - - - - diff --git a/FarmmapsZonering/Services/ZoneringService.cs b/FarmmapsZonering/Services/ZoneringService.cs index d736240..c6d717e 100644 --- a/FarmmapsZonering/Services/ZoneringService.cs +++ b/FarmmapsZonering/Services/ZoneringService.cs @@ -49,11 +49,10 @@ namespace FarmmapsZonering.Services return null; } - var itemName = $"VRAZonering"; var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, - GEOTIFF_PROCESSED_ITEMTYPE, itemName, + GEOTIFF_PROCESSED_ITEMTYPE, output.Name, i => i.Updated >= itemTask.Finished.GetValueOrDefault(DateTime.UtcNow) && - i.Name.ToLower().Contains(itemName.ToLower())); + i.Name.ToLower().Contains(output.Name.ToLower())); if (applianceMapItem == null) { From a94fb260c8be32ffc5d54a99f6bd03a3cbc8193a Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Wed, 3 Mar 2021 12:59:21 +0100 Subject: [PATCH 4/8] Changed ShapeToGeotiff --- FarmmapsApi/Services/GeneralService.cs | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index 36e5452..a415c07 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -71,11 +71,12 @@ namespace FarmmapsApi.Services public async Task ShapeToGeotiff(Item shapeItem) { + var startUpload = DateTime.UtcNow.AddSeconds(-3); await RunAndWaitForTask(shapeItem, "vnd.farmmaps.task.shapetogeotiff"); - // the parent of the shape item is now the tiff item - shapeItem = await _farmmapsApiService.GetItemAsync(shapeItem.Code); - return await _farmmapsApiService.GetItemAsync(shapeItem.ParentCode); + return await FindChildItemAsync(shapeItem.ParentCode, GEOTIFF_PROCESSED_ITEMTYPE, shapeItem.Name, + i => i.Created >= startUpload && + i.Name.ToLower().Contains(shapeItem.Name.ToLower())); } From beaf00a0435b28a02ad8cb99b607e7e8086794f5 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Sun, 11 Apr 2021 17:22:19 +0200 Subject: [PATCH 5/8] can now specify geojson bounds for upload. changed how to get agents for haulmkilling. --- FarmmapsApi/Services/FarmmapsApiService.cs | 4 ++- FarmmapsApi/Services/GeneralService.cs | 10 ++++---- .../HaulmkillingApplication.cs | 4 +-- FarmmapsHaulmkilling/HaulmkillingService.cs | 20 +++++++-------- .../Models/HaulmkillingAgent.cs | 25 ++++--------------- 5 files changed, 24 insertions(+), 39 deletions(-) diff --git a/FarmmapsApi/Services/FarmmapsApiService.cs b/FarmmapsApi/Services/FarmmapsApiService.cs index 1a2770b..6c18202 100644 --- a/FarmmapsApi/Services/FarmmapsApiService.cs +++ b/FarmmapsApi/Services/FarmmapsApiService.cs @@ -284,6 +284,7 @@ namespace FarmmapsApi.Services /// /// public async Task UploadFile(string filePath, string parentItemCode, + string geoJsonString = null, Action progressCallback = null) { if (!File.Exists(filePath)) @@ -300,7 +301,8 @@ namespace FarmmapsApi.Services { Name = Path.GetFileName(filePath), ParentCode = parentItemCode, - Size = uploadStream.Length + Size = uploadStream.Length, + Geometry = string.IsNullOrEmpty(geoJsonString) ? null : JObject.Parse(geoJsonString) }; using var httpClient = CreateConfigurableHttpClient(_httpClient); diff --git a/FarmmapsApi/Services/GeneralService.cs b/FarmmapsApi/Services/GeneralService.cs index a415c07..9e55854 100644 --- a/FarmmapsApi/Services/GeneralService.cs +++ b/FarmmapsApi/Services/GeneralService.cs @@ -41,10 +41,10 @@ namespace FarmmapsApi.Services return await _farmmapsApiService.CreateItemAsync(cropfieldItemRequest); } - public async Task UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName) + public async Task UploadDataAsync(UserRoot root, string itemType, string filePath, string itemName, string geoJsonString = null) { var startUpload = DateTime.UtcNow.AddSeconds(-3); - var result = await _farmmapsApiService.UploadFile(filePath, root.Code, + var result = await _farmmapsApiService.UploadFile(filePath, root.Code, geoJsonString, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); if (result.Progress.Status == UploadStatus.Failed) @@ -55,10 +55,10 @@ namespace FarmmapsApi.Services i.Name.ToLower().Contains(itemName.ToLower())); } - public async Task UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName) + public async Task UploadZipWithShapeAsync(UserRoot root, string filePath, string itemName, string geoJsonString = null) { - var startUpload = DateTime.UtcNow; - var result = await _farmmapsApiService.UploadFile(filePath, root.Code, + var startUpload = DateTime.UtcNow.AddSeconds(-3); + var result = await _farmmapsApiService.UploadFile(filePath, root.Code, geoJsonString, progress => _logger.LogInformation($"Status: {progress.Status} - BytesSent: {progress.BytesSent}")); if (result.Progress.Status == UploadStatus.Failed) diff --git a/FarmmapsHaulmkilling/HaulmkillingApplication.cs b/FarmmapsHaulmkilling/HaulmkillingApplication.cs index 272873d..bf57ac8 100644 --- a/FarmmapsHaulmkilling/HaulmkillingApplication.cs +++ b/FarmmapsHaulmkilling/HaulmkillingApplication.cs @@ -132,11 +132,11 @@ namespace FarmmapsHaulmkilling } var selectedAgent = agents[0]; - var selectedOption = selectedAgent.SupportedOptions[0]; + var selectedOption = selectedAgent.ValidOptions[0]; _logger.LogInformation("Calculating application map"); var applianceMapItem = await _haulmkillingService.CalculateApplicationMapAsync(cropfieldItem, - firstSatelliteItem, inputType, selectedAgent.Name, selectedOption); + firstSatelliteItem, inputType, selectedOption, selectedAgent); if (applianceMapItem == null) { return; diff --git a/FarmmapsHaulmkilling/HaulmkillingService.cs b/FarmmapsHaulmkilling/HaulmkillingService.cs index 98bd4d9..ff6f31e 100644 --- a/FarmmapsHaulmkilling/HaulmkillingService.cs +++ b/FarmmapsHaulmkilling/HaulmkillingService.cs @@ -6,6 +6,7 @@ using FarmmapsApi.Models; using FarmmapsApi.Services; using FarmmapsHaulmkilling.Models; using Microsoft.Extensions.Logging; +using Newtonsoft.Json; using static FarmmapsApi.Extensions; using static FarmmapsApiSamples.Constants; @@ -31,14 +32,11 @@ namespace FarmmapsHaulmkilling /// List of haulmkilling agents public async Task> GetHaulmkillingAgents() { - var itemType = "vnd.farmmaps.package.vra.haulmkilling"; - var vraHerbicideDataItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType); + var itemType = "vnd.farmmaps.itemtype.codelist.fm005"; + var haulmkillingAgentItems = await _farmmapsApiService.GetItemsAsync(string.Empty, itemType); - var item = vraHerbicideDataItems.FirstOrDefault(); - if (item == null) - return null; - - return item.Data.ContainsKey("agents") ? item.Data["agents"].ToObject>() : null; + return haulmkillingAgentItems.Select(item => item.Data.ToObject()) + .ToList(); } /// @@ -47,11 +45,11 @@ namespace FarmmapsHaulmkilling /// The context cropfield item to use /// The geotiff item to use /// WDVI or NDVI - /// One of the available agents + /// code of one of the available agents /// One of the available options /// Haulmkilling application map item public async Task CalculateApplicationMapAsync(Item cropfieldItem, Item inputItem, string inputType, - string agentName, string selectedOption) + string selectedOption, HaulmkillingAgent agent) { var taskRequest = new TaskRequest() { @@ -59,7 +57,7 @@ namespace FarmmapsHaulmkilling }; taskRequest.attributes["inputCode"] = inputItem.Code; taskRequest.attributes["inputType"] = inputType; - taskRequest.attributes["agentName"] = agentName; + taskRequest.attributes["agentCode"] = agent.Code; taskRequest.attributes["selectedOption"] = selectedOption; taskRequest.attributes["minPercentile"] = "0.0"; @@ -79,7 +77,7 @@ namespace FarmmapsHaulmkilling return null; } - var itemName = $"VRAHaulmkilling {agentName}"; + var itemName = $"VRAHaulmkilling {agent.Label}"; var applianceMapItem = await _generalService.FindChildItemAsync(cropfieldItem.Code, GEOTIFF_PROCESSED_ITEMTYPE, itemName, i => i.Updated >= itemTask.Finished && diff --git a/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs b/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs index 929197a..4f645f6 100644 --- a/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs +++ b/FarmmapsHaulmkilling/Models/HaulmkillingAgent.cs @@ -5,26 +5,11 @@ namespace FarmmapsHaulmkilling.Models { public class HaulmkillingAgent { - public string Name { get; set; } - public List SupportedOptions { get; set; } - public Dictionary> Values { get; set; } + public string Cl { get; set; } + public string Code { get; set; } + public string Label { get; set; } + public string Options { get; set; } - public HaulmkillingAgentValue? GetAgentValue(string inputName, string optionKey) - { - if (!Values.ContainsKey(inputName)) - return null; - - var agentDataValues = Values[inputName]; - return agentDataValues.FirstOrDefault(v => v.Option.Equals(optionKey)); - } - } - - public struct HaulmkillingAgentValue - { - public string Option { get; set; } - public float Min { get; set; } - public float Max { get; set; } - public float FMul { get; set; } - public float FExp { get; set; } + public List ValidOptions => Options.Split(',').ToList(); } } \ No newline at end of file From fefd3489303e04cb233f09dec975886cc2874ca8 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 19 Apr 2021 13:14:30 +0200 Subject: [PATCH 6/8] improved logging --- FarmmapsApi/FarmmapsApi.csproj | 14 ++++++++------ FarmmapsApi/FarmmapsProgram.cs | 24 +++++++++++++++++++++++- FarmmapsPoten/Program.cs | 4 +--- 3 files changed, 32 insertions(+), 10 deletions(-) diff --git a/FarmmapsApi/FarmmapsApi.csproj b/FarmmapsApi/FarmmapsApi.csproj index 8f133f8..46a26b6 100644 --- a/FarmmapsApi/FarmmapsApi.csproj +++ b/FarmmapsApi/FarmmapsApi.csproj @@ -6,13 +6,15 @@ - - - - - - + + + + + + + + diff --git a/FarmmapsApi/FarmmapsProgram.cs b/FarmmapsApi/FarmmapsProgram.cs index b1bc874..cc9ba5a 100644 --- a/FarmmapsApi/FarmmapsProgram.cs +++ b/FarmmapsApi/FarmmapsProgram.cs @@ -1,3 +1,4 @@ +using System; using System.Net.Http; using System.Threading.Tasks; using FarmmapsApi.HttpMessageHandlers; @@ -6,6 +7,10 @@ using FarmmapsApi.Services; using IdentityModel.Client; using Microsoft.Extensions.Configuration; using Microsoft.Extensions.DependencyInjection; +using Microsoft.Extensions.Logging; +using Serilog; +using Serilog.Events; +using Serilog.Filters; namespace FarmmapsApi { @@ -37,10 +42,12 @@ namespace FarmmapsApi .AddHttpMessageHandler() .Services; - Configure(serviceCollection); var serviceProvider = serviceCollection.BuildServiceProvider(); + + ConfigureLogger(serviceProvider); + await serviceProvider.GetService().AuthenticateAsync(); // await serviceProvider.GetService().StartEventHub(); @@ -48,5 +55,20 @@ namespace FarmmapsApi } protected abstract void Configure(IServiceCollection serviceCollection); + + private static void ConfigureLogger(IServiceProvider serviceProvider) + { + var isService = Matching.FromSource("Microsoft"); + + Log.Logger = new LoggerConfiguration() + .MinimumLevel.Information() + .WriteTo.Logger(l => l.Filter.ByIncludingOnly(isService) + .WriteTo.Console(LogEventLevel.Warning)) + .WriteTo.File(path: "Logs/log.log", rollingInterval: RollingInterval.Day) + .CreateLogger(); + + var loggerFactory = serviceProvider.GetRequiredService(); + loggerFactory.AddSerilog(); + } } } \ No newline at end of file diff --git a/FarmmapsPoten/Program.cs b/FarmmapsPoten/Program.cs index a3fa657..f9bcb48 100644 --- a/FarmmapsPoten/Program.cs +++ b/FarmmapsPoten/Program.cs @@ -14,9 +14,7 @@ namespace FarmmapsVRApoten protected override void Configure(IServiceCollection serviceCollection) { - serviceCollection.AddLogging(opts => opts - .AddConsole() - .AddFilter("System.Net.Http", LogLevel.Warning)) + serviceCollection.AddLogging() .AddTransient(); } } From 1b6128f52a4fddd123952d29d9ecd7a7e879e464 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 19 Apr 2021 13:16:33 +0200 Subject: [PATCH 7/8] small naming fix --- FarmmapsApi/FarmmapsProgram.cs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/FarmmapsApi/FarmmapsProgram.cs b/FarmmapsApi/FarmmapsProgram.cs index cc9ba5a..46e30d2 100644 --- a/FarmmapsApi/FarmmapsProgram.cs +++ b/FarmmapsApi/FarmmapsProgram.cs @@ -41,13 +41,13 @@ namespace FarmmapsApi .AddHttpClient() .AddHttpMessageHandler() .Services; - + Configure(serviceCollection); var serviceProvider = serviceCollection.BuildServiceProvider(); ConfigureLogger(serviceProvider); - + await serviceProvider.GetService().AuthenticateAsync(); // await serviceProvider.GetService().StartEventHub(); @@ -55,20 +55,20 @@ namespace FarmmapsApi } protected abstract void Configure(IServiceCollection serviceCollection); - + private static void ConfigureLogger(IServiceProvider serviceProvider) { - var isService = Matching.FromSource("Microsoft"); - + var isMicrosoftNamespace = Matching.FromSource("Microsoft"); + Log.Logger = new LoggerConfiguration() .MinimumLevel.Information() - .WriteTo.Logger(l => l.Filter.ByIncludingOnly(isService) + .WriteTo.Logger(l => l.Filter.ByIncludingOnly(isMicrosoftNamespace) .WriteTo.Console(LogEventLevel.Warning)) .WriteTo.File(path: "Logs/log.log", rollingInterval: RollingInterval.Day) .CreateLogger(); var loggerFactory = serviceProvider.GetRequiredService(); loggerFactory.AddSerilog(); - } + } } } \ No newline at end of file From e7de64d04c755c53d123d45263ca839077feaaf0 Mon Sep 17 00:00:00 2001 From: Mark van der Wal Date: Mon, 19 Apr 2021 14:03:43 +0200 Subject: [PATCH 8/8] improved logging again --- FarmmapsApi/FarmmapsProgram.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/FarmmapsApi/FarmmapsProgram.cs b/FarmmapsApi/FarmmapsProgram.cs index 46e30d2..ea25201 100644 --- a/FarmmapsApi/FarmmapsProgram.cs +++ b/FarmmapsApi/FarmmapsProgram.cs @@ -59,11 +59,15 @@ namespace FarmmapsApi private static void ConfigureLogger(IServiceProvider serviceProvider) { var isMicrosoftNamespace = Matching.FromSource("Microsoft"); + var isSystem = Matching.FromSource("System"); Log.Logger = new LoggerConfiguration() - .MinimumLevel.Information() - .WriteTo.Logger(l => l.Filter.ByIncludingOnly(isMicrosoftNamespace) - .WriteTo.Console(LogEventLevel.Warning)) + .MinimumLevel.Verbose() + .WriteTo.Logger(l => + l.WriteTo.Logger(l2 => l2 + .Filter.ByExcluding(v => isMicrosoftNamespace(v) || isSystem(v)) + .WriteTo.Console()) + ) .WriteTo.File(path: "Logs/log.log", rollingInterval: RollingInterval.Day) .CreateLogger();