|
1 | 1 | using System;
|
2 | 2 | using System.Collections.Generic;
|
3 | 3 | using System.Diagnostics;
|
| 4 | +using System.Reflection; |
4 | 5 | using Microsoft.AspNetCore.Builder;
|
5 | 6 | using Microsoft.AspNetCore.Http;
|
6 | 7 | using Exceptionless.AspNetCore;
|
| 8 | +using Exceptionless.Dependency; |
| 9 | +using Exceptionless.Logging; |
7 | 10 | using Exceptionless.Models;
|
8 | 11 | using Exceptionless.Models.Data;
|
9 | 12 | using Exceptionless.Plugins.Default;
|
| 13 | +using Exceptionless.Serializer; |
10 | 14 | using Exceptionless.Storage;
|
11 | 15 | using Microsoft.AspNetCore.Hosting;
|
12 | 16 | using Microsoft.Extensions.Configuration;
|
@@ -59,35 +63,64 @@ public static void ReadFromConfiguration(this ExceptionlessConfiguration config,
|
59 | 63 | throw new ArgumentNullException(nameof(settings));
|
60 | 64 |
|
61 | 65 | var section = settings.GetSection("Exceptionless");
|
62 |
| - |
| 66 | + if (Boolean.TryParse(section["Enabled"], out bool enabled) && !enabled) |
| 67 | + config.Enabled = false; |
| 68 | + |
63 | 69 | string apiKey = section["ApiKey"];
|
64 | 70 | if (!String.IsNullOrEmpty(apiKey) && apiKey != "API_KEY_HERE")
|
65 | 71 | config.ApiKey = apiKey;
|
66 | 72 |
|
67 |
| - foreach (var data in section.GetSection("DefaultData").GetChildren()) |
68 |
| - if (data.Value != null) |
69 |
| - config.DefaultData[data.Key] = data.Value; |
70 |
| - |
71 |
| - foreach (var tag in section.GetSection("DefaultTags").GetChildren()) |
72 |
| - config.DefaultTags.Add(tag.Value); |
73 |
| - |
74 |
| - if (Boolean.TryParse(section["Enabled"], out bool enabled) && !enabled) |
75 |
| - config.Enabled = false; |
76 |
| - |
77 |
| - if (Boolean.TryParse(section["IncludePrivateInformation"], out bool includePrivateInformation) && !includePrivateInformation) |
78 |
| - config.IncludePrivateInformation = false; |
79 |
| - |
80 | 73 | string serverUrl = section["ServerUrl"];
|
81 | 74 | if (!String.IsNullOrEmpty(serverUrl))
|
82 | 75 | config.ServerUrl = serverUrl;
|
| 76 | + |
| 77 | + if (TimeSpan.TryParse(section["QueueMaxAge"], out var queueMaxAge)) |
| 78 | + config.QueueMaxAge = queueMaxAge; |
83 | 79 |
|
| 80 | + if (Int32.TryParse(section["QueueMaxAttempts"], out int queueMaxAttempts)) |
| 81 | + config.QueueMaxAttempts = queueMaxAttempts; |
| 82 | + |
84 | 83 | string storagePath = section["StoragePath"];
|
85 | 84 | if (!String.IsNullOrEmpty(storagePath))
|
86 | 85 | config.Resolver.Register(typeof(IObjectStorage), () => new FolderObjectStorage(config.Resolver, storagePath));
|
87 | 86 |
|
| 87 | + string storageSerializer = section["StorageSerializer"]; |
| 88 | + if (!String.IsNullOrEmpty(storageSerializer)) { |
| 89 | + try { |
| 90 | + var serializerType = Type.GetType(storageSerializer); |
| 91 | + if (!typeof(IStorageSerializer).GetTypeInfo().IsAssignableFrom(serializerType)) { |
| 92 | + config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), $"The storage serializer {storageSerializer} does not implemented interface {typeof(IStorageSerializer)}."); |
| 93 | + } else { |
| 94 | + config.Resolver.Register(typeof(IStorageSerializer), serializerType); |
| 95 | + } |
| 96 | + } catch (Exception ex) { |
| 97 | + config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), ex, $"The storage serializer {storageSerializer} type could not be resolved: ${ex.Message}"); |
| 98 | + } |
| 99 | + } |
| 100 | + |
| 101 | + if (Boolean.TryParse(section["EnableLogging"], out bool enableLogging) && enableLogging) { |
| 102 | + string logPath = section["LogPath"]; |
| 103 | + if (!String.IsNullOrEmpty(logPath)) |
| 104 | + config.UseFileLogger(logPath); |
| 105 | + else if (!String.IsNullOrEmpty(storagePath)) |
| 106 | + config.UseFileLogger(System.IO.Path.Combine(storagePath, "exceptionless.log")); |
| 107 | + } |
| 108 | + |
| 109 | + if (Boolean.TryParse(section["IncludePrivateInformation"], out bool includePrivateInformation) && !includePrivateInformation) |
| 110 | + config.IncludePrivateInformation = false; |
| 111 | + |
| 112 | + foreach (var tag in section.GetSection("DefaultTags").GetChildren()) |
| 113 | + config.DefaultTags.Add(tag.Value); |
| 114 | + |
| 115 | + foreach (var data in section.GetSection("DefaultData").GetChildren()) |
| 116 | + if (data.Value != null) |
| 117 | + config.DefaultData[data.Key] = data.Value; |
| 118 | + |
88 | 119 | foreach (var setting in section.GetSection("Settings").GetChildren())
|
89 | 120 | if (setting.Value != null)
|
90 | 121 | config.Settings[setting.Key] = setting.Value;
|
| 122 | + |
| 123 | + // TODO: Support Registrations |
91 | 124 | }
|
92 | 125 |
|
93 | 126 | /// <summary>
|
|
0 commit comments