@@ -45,7 +45,29 @@ public class EventGridTarget : AsyncTaskTarget
4545 /// <summary>
4646 /// Content type of the payload. A content type different from "application/json" should be specified if payload is not JSON.
4747 /// </summary>
48- public Layout ContentType { get ; set ; }
48+ public Layout ContentType
49+ {
50+ get => _contentType ;
51+ set
52+ {
53+ _contentType = value ;
54+ if ( ! _dataFormatJson . HasValue && value ? . ToString ( ) ? . IndexOf ( "json" , StringComparison . OrdinalIgnoreCase ) >= 0 )
55+ {
56+ _dataFormatJson = true ;
57+ }
58+ }
59+ }
60+ private Layout _contentType ;
61+
62+ /// <summary>
63+ /// The serialize format of the data object. Json / Binary
64+ /// </summary>
65+ public string DataFormat
66+ {
67+ get => _dataFormatJson == true ? "Json" : "Binary" ;
68+ set => _dataFormatJson = value ? . IndexOf ( "Json" , StringComparison . OrdinalIgnoreCase ) >= 0 ;
69+ }
70+ private bool ? _dataFormatJson ;
4971
5072 /// <summary>
5173 /// The schema version of the data object.
@@ -207,7 +229,7 @@ private CloudEvent CreateCloudEvent(LogEventInfo logEvent)
207229 var eventType = RenderLogEvent ( EventType , logEvent ) ?? string . Empty ;
208230 var eventDataSchema = RenderLogEvent ( DataSchema , logEvent ) ?? string . Empty ;
209231 var eventContentType = RenderLogEvent ( ContentType , logEvent ) ?? string . Empty ;
210- var cloudEventFormat = Layout is JsonLayout ? CloudEventDataFormat . Json : CloudEventDataFormat . Binary ;
232+ var cloudEventFormat = _dataFormatJson == true ? CloudEventDataFormat . Json : CloudEventDataFormat . Binary ;
211233 var cloudEvent = new CloudEvent ( eventSource , eventType , new BinaryData ( EncodeToUTF8 ( eventDataBody ) ) , eventContentType , cloudEventFormat ) ;
212234 cloudEvent . Time = logEvent . TimeStamp . ToUniversalTime ( ) ;
213235
0 commit comments