Witam.
Pisze programik do łączenia się z ElasticSearch.
na stronie znalazłem opis jak trzeba to zrobić i wygląda to tak:
private void button1_Click(object sender, EventArgs e)
{
var Polaczenie = new Uri("http://localhost:9200");
var Settings = new ConnectionSettings(Polaczenie, defaultIndex: "logsystem");
var Klient = new ElasticClient(Settings);
for (var i = 1; i <= 50; i++)
{
var Log = new Log("1", "2016-02-06T09:01:01", "INFO", "tekst");
var index = Klient.Index(Log);
}
}
public class Log
{
public string id { get; set; }
public string date { get; set; }
public string type { get; set; }
public string content { get; set; }
public Log(string id, string date, string type, string content)
{
this.id = id;
this.date = date;
this.type = type;
this.content = content;
}
Tylko jak tak to zrobię to obiekty Uri, ConnectionSettings i ElasticClient są widoczne tylko w zdarzeniu buttona.
zmodyfikowałem sobie kod aby w/w obiekty były widziane w całym programie natomiast wysyłanie logów zrobiłem w zdarzeniu timelog_Tick
namespace GeneratorLog
{
public partial class Form1 : Form
{
Uri Polaczenie;
ConnectionSettings Settings;
ElasticClient Klient;
Log LogTxt;
String TypText, InfoText, InfoMilisekunda, SendLog, DataText, IDText;
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
ViewLog.Clear();
TextIP.Enabled = false;
TextPort.Enabled = false;
Polaczenie = new Uri("http://"+TextIP.Text+":"+TextPort.Text);
Settings = new ConnectionSettings(Polaczenie, defaultIndex: "genlog");
Klient = new ElasticClient(Settings);
}
private void TimeLog_Tick(object sender, EventArgs e)
{
IDText = ("1");
DataText = (System.DateTime.Now);
TypText = "INFO ";
InfoText = ("Informacja");
LogTxt = new Log(IDText, DataText, TypText, InfoText);
Klient.Index(LogTxt);
}
public class Log
{
public string id { get; set; }
public string date { get; set; }
public string type { get; set; }
public string content { get; set; }
public Log(string id, string date, string type, string content)
{
this.id = id;
this.date = date;
this.type = type;
this.content = content;
}
i teraz nie wiem czy to jest poprawnie ;-( - program się kompiluje i uruchamia ale logi nie są wysyłane i nie wiem czy program działa poprawnie czy logi są nieprawidłowe.