/// <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); }
private static ISource CreateEventSourceWithDelimitedLogParser(IPlugInContext context, string timestampFormat, DateTimeKind timeZoneKind) { DelimitedLogParser parser = CreateDelimitedLogParser(context, timestampFormat, timeZoneKind); return(CreateEventSource( context, parser)); }