1
1
using System ;
2
- using System . Reflection ;
3
- using Exceptionless . Dependency ;
4
2
using Exceptionless . Extensions . Hosting ;
5
- using Exceptionless . Logging ;
6
- using Exceptionless . Serializer ;
7
- using Exceptionless . Storage ;
8
3
using Microsoft . Extensions . Configuration ;
9
4
using Microsoft . Extensions . DependencyInjection ;
10
5
using Microsoft . Extensions . Hosting ;
@@ -83,81 +78,5 @@ public static IServiceCollection AddExceptionless(this IServiceCollection servic
83
78
return client ;
84
79
} ) ;
85
80
}
86
-
87
- /// <summary>
88
- /// Sets the configuration from .net configuration settings.
89
- /// </summary>
90
- /// <param name="config">The configuration object you want to apply the settings to.</param>
91
- /// <param name="settings">The configuration settings</param>
92
- public static void ReadFromConfiguration ( this ExceptionlessConfiguration config , IConfiguration settings ) {
93
- if ( config == null )
94
- throw new ArgumentNullException ( nameof ( config ) ) ;
95
-
96
- if ( settings == null )
97
- throw new ArgumentNullException ( nameof ( settings ) ) ;
98
-
99
- var section = settings . GetSection ( "Exceptionless" ) ;
100
- if ( Boolean . TryParse ( section [ "Enabled" ] , out bool enabled ) && ! enabled )
101
- config . Enabled = false ;
102
-
103
- string apiKey = section [ "ApiKey" ] ;
104
- if ( ! String . IsNullOrEmpty ( apiKey ) && apiKey != "API_KEY_HERE" )
105
- config . ApiKey = apiKey ;
106
-
107
- string serverUrl = section [ "ServerUrl" ] ;
108
- if ( ! String . IsNullOrEmpty ( serverUrl ) )
109
- config . ServerUrl = serverUrl ;
110
-
111
- if ( TimeSpan . TryParse ( section [ "QueueMaxAge" ] , out var queueMaxAge ) )
112
- config . QueueMaxAge = queueMaxAge ;
113
-
114
- if ( Int32 . TryParse ( section [ "QueueMaxAttempts" ] , out int queueMaxAttempts ) )
115
- config . QueueMaxAttempts = queueMaxAttempts ;
116
-
117
- string storagePath = section [ "StoragePath" ] ;
118
- if ( ! String . IsNullOrEmpty ( storagePath ) )
119
- config . Resolver . Register ( typeof ( IObjectStorage ) , ( ) => new FolderObjectStorage ( config . Resolver , storagePath ) ) ;
120
-
121
- string storageSerializer = section [ "StorageSerializer" ] ;
122
- if ( ! String . IsNullOrEmpty ( storageSerializer ) ) {
123
- try {
124
- var serializerType = Type . GetType ( storageSerializer ) ;
125
- if ( ! typeof ( IStorageSerializer ) . GetTypeInfo ( ) . IsAssignableFrom ( serializerType ) ) {
126
- config . Resolver . GetLog ( ) . Error ( typeof ( ExceptionlessConfigurationExtensions ) , $ "The storage serializer { storageSerializer } does not implemented interface { typeof ( IStorageSerializer ) } .") ;
127
- } else {
128
- config . Resolver . Register ( typeof ( IStorageSerializer ) , serializerType ) ;
129
- }
130
- } catch ( Exception ex ) {
131
- config . Resolver . GetLog ( ) . Error ( typeof ( ExceptionlessConfigurationExtensions ) , ex , $ "The storage serializer { storageSerializer } type could not be resolved: ${ ex . Message } ") ;
132
- }
133
- }
134
-
135
- if ( Boolean . TryParse ( section [ "EnableLogging" ] , out bool enableLogging ) && enableLogging ) {
136
- string logPath = section [ "LogPath" ] ;
137
- if ( ! String . IsNullOrEmpty ( logPath ) )
138
- config . UseFileLogger ( logPath ) ;
139
- else if ( ! String . IsNullOrEmpty ( storagePath ) )
140
- config . UseFileLogger ( System . IO . Path . Combine ( storagePath , "exceptionless.log" ) ) ;
141
- }
142
-
143
- if ( Boolean . TryParse ( section [ "IncludePrivateInformation" ] , out bool includePrivateInformation ) && ! includePrivateInformation )
144
- config . IncludePrivateInformation = false ;
145
-
146
- if ( Boolean . TryParse ( section [ "ProcessQueueOnCompletedRequest" ] , out bool processQueueOnCompletedRequest ) && processQueueOnCompletedRequest )
147
- config . ProcessQueueOnCompletedRequest = true ;
148
-
149
- foreach ( var tag in section . GetSection ( "DefaultTags" ) . GetChildren ( ) )
150
- config . DefaultTags . Add ( tag . Value ) ;
151
-
152
- foreach ( var data in section . GetSection ( "DefaultData" ) . GetChildren ( ) )
153
- if ( data . Value != null )
154
- config . DefaultData [ data . Key ] = data . Value ;
155
-
156
- foreach ( var setting in section . GetSection ( "Settings" ) . GetChildren ( ) )
157
- if ( setting . Value != null )
158
- config . Settings [ setting . Key ] = setting . Value ;
159
-
160
- // TODO: Support Registrations
161
- }
162
81
}
163
82
}
0 commit comments