mirror of
https://github.com/ClemensFischer/XAML-Map-Control.git
synced 2026-01-23 17:10:25 +01:00
Use Microsoft.Extensions.Logging
This commit is contained in:
parent
4c5321958a
commit
4a3be1e130
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Xml.Linq;
|
||||
|
|
@ -55,12 +55,12 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(BingMapsTileLayer)}: {metadataUri}: {ex.Message}");
|
||||
ImageLoader.LoggerFactory?.CreateLogger<BingMapsTileLayer>()?.LogError(ex, "{uri}", metadataUri);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"{nameof(BingMapsTileLayer)} requires a Bing Maps API Key");
|
||||
ImageLoader.LoggerFactory?.CreateLogger<BingMapsTileLayer>()?.LogError("Bing Maps API Key required");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -113,7 +113,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(GeoImage)}: {sourcePath}: {ex.Message}");
|
||||
ImageLoader.LoggerFactory?.CreateLogger(typeof(GeoImage))?.LogError(ex, "{sourcePath}", sourcePath);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.IO.Compression;
|
||||
|
|
@ -80,7 +80,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(GroundOverlay)}: {sourcePath}: {ex.Message}");
|
||||
ImageLoader.LoggerFactory?.CreateLogger<GroundOverlay>()?.LogError(ex, "{sourcePath}", sourcePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
|
|
@ -17,14 +17,19 @@ namespace MapControl
|
|||
{
|
||||
public static partial class ImageLoader
|
||||
{
|
||||
private static ILogger logger;
|
||||
private static ILogger Logger => logger ?? (logger = LoggerFactory?.CreateLogger(typeof(ImageLoader)));
|
||||
|
||||
public static ILoggerFactory LoggerFactory { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// The System.Net.Http.HttpClient instance used to download images via a http or https Uri.
|
||||
/// </summary>
|
||||
public static HttpClient HttpClient { get; set; } = new HttpClient();
|
||||
public static HttpClient HttpClient { get; set; }
|
||||
|
||||
static ImageLoader()
|
||||
{
|
||||
HttpClient.Timeout = TimeSpan.FromSeconds(30);
|
||||
HttpClient = new HttpClient { Timeout = TimeSpan.FromSeconds(30) };
|
||||
HttpClient.DefaultRequestHeaders.Add("User-Agent", $"XAML-Map-Control/{typeof(ImageLoader).Assembly.GetName().Version}");
|
||||
}
|
||||
|
||||
|
|
@ -56,7 +61,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(ImageLoader)}: {uri}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{uri}", uri);
|
||||
}
|
||||
|
||||
progress?.Report(1d);
|
||||
|
|
@ -117,13 +122,13 @@ namespace MapControl
|
|||
}
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"{nameof(ImageLoader)}: {uri}: {(int)responseMessage.StatusCode} {responseMessage.ReasonPhrase}");
|
||||
Logger?.LogWarning("{uri}: {status} {reason}", uri, (int)responseMessage.StatusCode, responseMessage.ReasonPhrase);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(ImageLoader)}: {uri}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{uri}", uri);
|
||||
}
|
||||
|
||||
return response;
|
||||
|
|
|
|||
|
|
@ -187,7 +187,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(MapImageLayer)}: {ex.Message}");
|
||||
Debug.WriteLine($"MapImageLayer.GetImageAsync: {ex.Message}");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,7 +1,5 @@
|
|||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.Specialized;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -107,22 +105,13 @@ namespace MapControl
|
|||
FrameworkElement overlay;
|
||||
var ext = Path.GetExtension(sourcePath).ToLower();
|
||||
|
||||
try
|
||||
if (ext == ".kmz" || ext == ".kml")
|
||||
{
|
||||
if (ext == ".kmz" || ext == ".kml")
|
||||
{
|
||||
overlay = await GroundOverlay.CreateAsync(sourcePath);
|
||||
}
|
||||
else
|
||||
{
|
||||
overlay = await GeoImage.CreateAsync(sourcePath);
|
||||
}
|
||||
overlay = await GroundOverlay.CreateAsync(sourcePath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
else
|
||||
{
|
||||
Debug.WriteLine($"{nameof(MapOverlaysPanel)}: {sourcePath}: {ex.Message}");
|
||||
|
||||
overlay = new MapPanel();
|
||||
overlay = await GeoImage.CreateAsync(sourcePath);
|
||||
}
|
||||
|
||||
return overlay;
|
||||
|
|
|
|||
|
|
@ -175,7 +175,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(MapPanel)}.ArrangeOverride: {element}: {ex.Message}");
|
||||
Debug.WriteLine($"MapPanel.ArrangeOverride: {element}: {ex.Message}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
using Microsoft.Extensions.Caching.Distributed;
|
||||
using Microsoft.Extensions.Caching.Memory;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using Microsoft.Extensions.Options;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -59,6 +59,9 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public static int MaxLoadTasks { get; set; } = 4;
|
||||
|
||||
private static ILogger logger;
|
||||
private static ILogger Logger => logger ?? (logger = ImageLoader.LoggerFactory?.CreateLogger<TileImageLoader>());
|
||||
|
||||
private ConcurrentStack<Tile> pendingTiles;
|
||||
|
||||
/// <summary>
|
||||
|
|
@ -102,7 +105,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(TileImageLoader)}: {tile.ZoomLevel}/{tile.Column}/{tile.Row}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{zoom}/{column}/{row}", tile.ZoomLevel, tile.Column, tile.Row);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -161,7 +164,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(TileImageLoader)}.{nameof(Cache)}.GetAsync: {cacheKey}: {ex.Message}");
|
||||
Logger?.LogError(ex, "Cache.GetAsync: {cacheKey}", cacheKey);
|
||||
}
|
||||
|
||||
if (buffer == null)
|
||||
|
|
@ -185,7 +188,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(TileImageLoader)}.{nameof(Cache)}.SetAsync: {cacheKey}: {ex.Message}");
|
||||
Logger?.LogError(ex, "Cache.SetAsync: {cacheKey}", cacheKey);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Globalization;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -23,6 +23,9 @@ namespace MapControl
|
|||
/// </summary>
|
||||
public class WmsImageLayer : MapImageLayer
|
||||
{
|
||||
private static ILogger logger;
|
||||
private static ILogger Logger => logger ?? (logger = ImageLoader.LoggerFactory?.CreateLogger<WmsImageLayer>());
|
||||
|
||||
public static readonly DependencyProperty ServiceUriProperty =
|
||||
DependencyPropertyHelper.Register<WmsImageLayer, Uri>(nameof(ServiceUri), null,
|
||||
async (layer, oldValue, newValue) => await layer.UpdateImageAsync());
|
||||
|
|
@ -114,7 +117,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(WmsImageLayer)}: {uri}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{uri}", uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -146,7 +149,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(WmsImageLayer)}: {uri}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{uri}", uri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -366,7 +369,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(WmsImageLayer)}: {uri}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{uri}", uri);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
using System;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Diagnostics;
|
||||
using System.Linq;
|
||||
using System.Threading.Tasks;
|
||||
#if WPF
|
||||
|
|
@ -200,7 +200,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(WmtsTileLayer)}: {CapabilitiesUri}: {ex.Message}");
|
||||
ImageLoader.LoggerFactory?.CreateLogger<WmtsTileLayer>()?.LogError(ex, "{uri}", CapabilitiesUri);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
using System;
|
||||
using System.Diagnostics;
|
||||
using Microsoft.Extensions.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Runtime.InteropServices.WindowsRuntime;
|
||||
using System.Threading.Tasks;
|
||||
|
|
@ -89,7 +89,7 @@ namespace MapControl
|
|||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Debug.WriteLine($"{nameof(ImageLoader)}: {uri}: {ex.Message}");
|
||||
Logger?.LogError(ex, "{uri}", uri);
|
||||
}
|
||||
|
||||
progress.Report(1d);
|
||||
|
|
|
|||
Loading…
Reference in a new issue