/// <summary> /// Create delimited parser /// </summary> /// <param name="context">Plug-in context</param> /// <param name="timestampFormat">Timestamp format</param> /// <param name="timeZoneKind">Timezone Kind</param> /// <returns>Delimited log parser</returns> public static DelimitedLogParser CreateDelimitedLogParser(IPlugInContext context, string timestampFormat, DateTimeKind timeZoneKind) { IConfiguration config = context.Configuration; string delimiter = config["Delimiter"]; string timestampField = config["TimestampField"]; //Validate required attributes Guard.ArgumentNotNullOrEmpty(delimiter, "Delimiter is required for DelimitedLogParser"); Guard.ArgumentNotNullOrEmpty(timestampFormat, "TimestampFormat is required for DelimitedLogParser"); Guard.ArgumentNotNullOrEmpty(timestampField, "TimestampField is required for DelimitedLogParser"); var delimitedLogTimestampExtractor = new TimestampExtrator(timestampField, timestampFormat); string commentPattern = config["CommentPattern"]; string headerPattern = config["HeaderPattern"]; string recordPattern = config["RecordPattern"]; string headers = config["Headers"]; DelimitedLogRecord recordFactoryMethod(string[] data, DelimitedLogContext logContext) => new DelimitedLogRecord(data, logContext, delimitedLogTimestampExtractor.GetTimestamp); var parser = new DelimitedLogParser(context, delimiter, recordFactoryMethod, headerPattern, recordPattern, commentPattern, headers, timeZoneKind); return(parser); }
public SingleLineJsonParser(string timestampField, string timestampFormat) { if (!string.IsNullOrEmpty(timestampField) || !string.IsNullOrEmpty(timestampFormat)) { //If one is provided, then timestampField is required Guard.ArgumentNotNullOrEmpty(timestampField, "TimestampField is required for SingleLineJsonParser"); TimestampExtrator timestampExtractor = new TimestampExtrator(timestampField, timestampFormat); _getTimestamp = timestampExtractor.GetTimestamp; } else { _getTimestamp = jobject => DateTime.UtcNow; } }