<#@ output extension=".sql" #> <#@ template language="C#" hostspecific="True" #> SELECT * FROM OPENROWSET(BULK '<#=this.Host.ResolvePath("..\\logs") #>\log-20170203.ndjson', FORMATFILE = '<#=this.Host.ResolvePath("..\\logs") #>\linedelimited.fmt' ) as logs; DROP TABLE IF EXISTS Logs --{"Timestamp":"2017-02-03T08:33:32.0776155+01:00","Level":"Information","MessageTemplate":"{HostingRequestFinished:l}","Properties":{"ElapsedMilliseconds":154.2332,"StatusCode":200,"ContentType":null,"HostingRequestFinished":"Request finished in 154.2332ms 200 ","EventId":{"Id":2},"SourceContext":"Microsoft.AspNetCore.Hosting.Internal.WebHost","RequestId":"0HL2C0RQ64LNN","RequestPath":"/"},"Renderings":{"HostingRequestFinished":[{"Format":"l","Rendering":"Request finished in 154.2332ms 200 "}]}} CREATE TABLE Logs ( Data NVARCHAR(MAX), Timestamp AS CAST(JSON_VALUE(Data, '$.Timestamp') as datetime2), Level AS CAST(JSON_VALUE(Data, '$.Level') as nvarchar(40)), ElapsedMilliseconds AS CAST(JSON_VALUE(Data, '$.Properties.ElapsedMilliseconds') AS float), StatusCode AS CAST(JSON_VALUE(Data, '$.Properties.StatusCode') AS int) ) BULK INSERT Logs FROM '<#=this.Host.ResolvePath("..\\logs") #>\log-20170203.ndjson' WITH (FORMATFILE = '<#=this.Host.ResolvePath("..\\logs") #>\linedelimited.fmt')