Skip to content

Commit f3d4ac4

Browse files
committed
Fixed #136 issue where adding a trace listener could blow up.
1 parent acdf37c commit f3d4ac4

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

src/Exceptionless/Extensions/ExceptionlessConfigurationExtensions.cs

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -225,15 +225,19 @@ public static void UseFolderStorage(this ExceptionlessConfiguration config, stri
225225
}
226226

227227
public static void UseTraceLogEntriesPlugin(this ExceptionlessConfiguration config, int? defaultMaxEntriesToInclude = null) {
228-
int maxEntriesToInclude = config.Settings.GetInt32(TraceLogPlugin.MaxEntriesToIncludeKey, defaultMaxEntriesToInclude ?? 0);
228+
try {
229+
int maxEntriesToInclude = config.Settings.GetInt32(TraceLogPlugin.MaxEntriesToIncludeKey, defaultMaxEntriesToInclude ?? 0);
229230

230-
if (!Trace.Listeners.OfType<ExceptionlessTraceListener>().Any())
231-
Trace.Listeners.Add(new ExceptionlessTraceListener(maxEntriesToInclude));
231+
if (!Trace.Listeners.OfType<ExceptionlessTraceListener>().Any())
232+
Trace.Listeners.Add(new ExceptionlessTraceListener(maxEntriesToInclude));
232233

233-
if (!config.Settings.ContainsKey(TraceLogPlugin.MaxEntriesToIncludeKey) && defaultMaxEntriesToInclude.HasValue)
234-
config.Settings.Add(TraceLogPlugin.MaxEntriesToIncludeKey, maxEntriesToInclude.ToString());
234+
if (!config.Settings.ContainsKey(TraceLogPlugin.MaxEntriesToIncludeKey) && defaultMaxEntriesToInclude.HasValue)
235+
config.Settings.Add(TraceLogPlugin.MaxEntriesToIncludeKey, maxEntriesToInclude.ToString());
235236

236-
config.AddPlugin(typeof(TraceLogPlugin).Name, 70, c => new TraceLogPlugin(c));
237+
config.AddPlugin(typeof(TraceLogPlugin).Name, 70, c => new TraceLogPlugin(c));
238+
} catch (Exception ex) {
239+
config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), ex, String.Concat("Error adding ExceptionlessTraceListener: ", ex.Message));
240+
}
237241
}
238242
#endif
239243

@@ -281,7 +285,7 @@ public static void ReadFromConfigSection(this ExceptionlessConfiguration config)
281285
try {
282286
section = ConfigurationManager.GetSection("exceptionless") as ExceptionlessSection;
283287
} catch (Exception ex) {
284-
config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), ex, String.Concat("An error occurred while retrieving the configuration section. Exception: ", ex.Message));
288+
config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), ex, String.Concat("Error retrieving configuration section: ", ex.Message));
285289
}
286290

287291
if (section == null)
@@ -340,7 +344,7 @@ public static void ReadFromConfigSection(this ExceptionlessConfiguration config)
340344

341345
Type resolverInterface = types.FirstOrDefault(t => t.Name.Equals(resolver.Service) || t.FullName.Equals(resolver.Service));
342346
if (resolverInterface == null) {
343-
config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), String.Format("An error occurred while retrieving service type \"{0}\".", resolver.Service));
347+
config.Resolver.GetLog().Error(typeof(ExceptionlessConfigurationExtensions), String.Format("Error retrieving service type \"{0}\".", resolver.Service));
344348
continue;
345349
}
346350

0 commit comments

Comments
 (0)