/// <summary> /// Factory method to create instance /// </summary> /// <param name="entry">Name of the factory</param> /// <param name="context">Context supplied by the infrastructure</param> /// <returns>Instance instantiated by the factory.</returns> public IRecordParser CreateInstance(string entry, IPlugInContext context) { IConfiguration config = context.Configuration; ILogger logger = context.Logger; string timetampFormat = config["TimestampFormat"]; string timestampField = config["TimestampField"]; switch (entry.ToLower()) { case SINGLE_LINE_JSON2: return(new SingleLineJsonParser(timestampField, timetampFormat, NullLogger.Instance)); case DELIMITED2: DateTimeKind timeZoneKind = DateTimeKind.Utc; //Default string timeZoneKindConfig = Utility.ProperCase(config["TimeZoneKind"]); if (!string.IsNullOrWhiteSpace(timeZoneKindConfig)) { timeZoneKind = (DateTimeKind)Enum.Parse(typeof(DateTimeKind), timeZoneKindConfig); } return(DirectorySourceFactory.CreateDelimitedLogParser(context, timetampFormat, timeZoneKind)); default: throw new ArgumentException($"Parser {entry} not recognized."); } }
private static List <IEnvelope <DelimitedLogRecord> > ParseRecords(StreamReader sr, Microsoft.Extensions.Configuration.IConfigurationSection config) { string timetampFormat = config["TimestampFormat"]; var parser = DirectorySourceFactory.CreateDelimitedLogParser(new PluginContext(config, null, null, new BookmarkManager()), timetampFormat, DateTimeKind.Utc); var records = parser.ParseRecords(sr, new DelimitedLogContext()).ToList(); return(records); }
public void TestNonGenericCreateEventSourceWithDelimitedParser() { var config = TestUtility.GetConfig("Sources", "DHCPParsed"); string timestampField = config["TimestampField"]; PluginContext context = new PluginContext(config, null, null); IRecordParser parser = DirectorySourceFactory.CreateDelimitedLogParser(context, timestampField, DateTimeKind.Utc); var source = DirectorySourceFactory.CreateEventSource(context, parser); Assert.NotNull(source); Assert.IsType <DirectorySource <DelimitedLogRecord, DelimitedLogContext> >(source); }