Ahoj, chtěl bych poradit. Mám kód, který projíždí *log a vyhazuje výstup IP adresu Port, Datum a Stav - jestli ok nebo disconnected. Nyní bych potřeboval, aby se tento stav ocitl na vytvořené webové aplikaci. Data se posílají přes API a json. Tzn. mám *log, kde zjistím například "ip: 198.182.168.2:10050 12.5.2017 11:45:02 ... OK" a tohle bych chtěl upravit na json, který se bude posílat přes API. Json by měl vypadat takhle: "{\"ufid\":\"AAA-BB-CCCCCCC-DDDD\"," + "\"utype\":\"XXX\"," + "\"timestamp\":\"2017-12-05T11:45:02.0Z\"," + "\"status\":\"Ok\"}";Důležitý je ufid a status. Těchto ufidů je asi 200. Prochází se každý řádek z logu a každý je jiný tzn., že to vybere řádek ip port time a stav a pošle json se stavem přes API. Pro jistotu posílám celý kód.Kód: using System;using System.Collections.Generic;using System.IO;using System.Linq;using System.Text.RegularExpressions;namespace TesterCon7{ class OutputItem { public DateTime Date; public string IPPort; public string State; } class Program2 { //nastaveni stavu PushButton const String OkState = "OK"; const String FailState = "Nefunkcni"; const String UnknownState = "Nenalezen odpovidajici stav"; const String InputFile = @"C:\Users\XXX\Desktop\20170512.log"; static Regex[] parser = new Regex[]{… new Regex(@"<(.*?)>: --- Open a new connection: ([0-9.]+) - ([0-9]+) -------", RegexOptions.Compiled), new Regex(@".*", RegexOptions.Compiled) // Vyber slov ze souboru }; static Dictionary<string, OutputItem> ActualStates = new Dictionary<string, OutputItem>(); // definovani actualStates private static void ProcessLogRecord(Match[] parsed) { DateTime dt = DateTime.Parse(parsed[0].Groups[1].Value, System.Globalization.CultureInfo.GetCultureInfo("en-us")); if (dt > DateTime.Now.AddHours(-10000)) // Mezeni vyberu casu do urcite hodiny { var item = new OutputItem(); // definovani vystupni polozky item.Date = dt; item.State = UnknownState; if (parsed[1].Value.Contains("succesfull")) item.State = OkState; else if (parsed[1].Value.Contains("failed")) item.State = FailState; item.IPPort = string.Format("{0}:{1}", parsed[0].Groups[2].Value, parsed[0].Groups[3].Value); if (ActualStates.ContainsKey(item.IPPort)) { if (item.Date > ActualStates[item.IPPort].Date) ActualStates[item.IPPort] = item; } else { ActualStates[item.IPPort] = item; } } } static void Main(string[] args) { Match[] parsed = new Match[parser.Count()]; int index = 0; try { foreach (var line in File.ReadLines(InputFile)) // cteni souboru v liniich { parsed[index] = parser[index].Match(line); if (!parsed[index++].Success) index = 0; if (index >= parsed.Length) { ProcessLogRecord(parsed); index = 0; } } StreamWriter outfile = new StreamWriter(@"C:\Users\XXX\Desktop\Programy\YYY.log"); Console.WriteLine("zacina vypis"); foreach (var x in ActualStates) { Console.WriteLine(String.Format("ip: {0} {1} ... {2}", x.Value.IPPort, x.Value.Date, x.Value.State)); } Console.WriteLine("konci vypis"); Console.ReadKey(); } catch (Exception e) { Console.Error.WriteLine("Error: {0}", e); } } }}Děkuji za každou radu. Ukázat celý příspěvek