@@ -28,15 +28,17 @@ public ExceptionlessTarget() {
2828 protected override void InitializeTarget ( ) {
2929 base . InitializeTarget ( ) ;
3030
31- foreach ( var field in Fields ) {
32- if ( field == null )
33- throw new NLogConfigurationException ( "Exceptionless field configuration cannot be null." ) ;
31+ if ( Fields != null ) {
32+ foreach ( var field in Fields ) {
33+ if ( field == null )
34+ throw new NLogConfigurationException ( "Exceptionless field configuration cannot be null." ) ;
3435
35- if ( String . IsNullOrWhiteSpace ( field . Name ) )
36- throw new NLogConfigurationException ( "Exceptionless field name is required." ) ;
36+ if ( String . IsNullOrWhiteSpace ( field . Name ) )
37+ throw new NLogConfigurationException ( "Exceptionless field name is required." ) ;
3738
38- if ( field . Layout == null )
39- throw new NLogConfigurationException ( $ "Exceptionless field '{ field . Name } ' must define a layout.") ;
39+ if ( field . Layout == null )
40+ throw new NLogConfigurationException ( $ "Exceptionless field '{ field . Name } ' must define a layout.") ;
41+ }
4042 }
4143
4244 string apiKey = RenderLogEvent ( ApiKey , LogEventInfo . CreateNullEvent ( ) ) ;
@@ -80,10 +82,12 @@ protected override void Write(LogEventInfo logEvent) {
8082 string userIdentityName = RenderLogEvent ( UserIdentityName , logEvent ) ;
8183 builder . Target . SetUserIdentity ( userIdentity , userIdentityName ) ;
8284
83- foreach ( var field in Fields ) {
84- string renderedField = RenderLogEvent ( field . Layout , logEvent ) ;
85- if ( ! String . IsNullOrWhiteSpace ( renderedField ) )
86- builder . AddObject ( renderedField , field . Name ) ;
85+ if ( Fields != null ) {
86+ foreach ( var field in Fields ) {
87+ string renderedField = RenderLogEvent ( field . Layout , logEvent ) ;
88+ if ( ! String . IsNullOrWhiteSpace ( renderedField ) )
89+ builder . AddObject ( renderedField , field . Name ) ;
90+ }
8791 }
8892
8993 builder . Submit ( ) ;
0 commit comments