Closed qiqistart closed 3 years ago
Hello, @huzitao!
Sorry, can't get about what index do u talk? Do u mean a search index, used for indexation of log entries?
yes
Main principles of Loki differs from a principles of Elastic Search.
Traditional systems like ELK parse log strings entirely, including fields with a lot of unique values (for example, UserId from log entry) and save parsed data into big indexes. It has advantage that queries could be done fast, cause all required data is in the index. But the disadvantage is an index grows and become very large (in most cases size of the index could be almost equal to a logs size).
Loki works in another way. It's approach requires only most critical data must be extracted into index (called labels). So u have a possibility to find data, using filtration by datetime & labels. And the u could do an additional filtering with LogQL (it's kinda a regex & substring-based language).
U could find more details in Loki documentation.
So, for that approach you should determine most important fields for indexing and setup the sync with filtrationMode Include
and filtrationLabels list.
For example:
ILogger logger = new LoggerConfiguration()
.WriteTo.GrafanaLoki(
"http://localhost:3100",
filtrationMode: LokiLabelFiltrationMode.Include,
filtrationLabels: new [] {"RequestId", "ClientIp", "SomeImportantLogValue"})
.CreateLogger();
More examples of filtering are here in tests
thank you very much
Thank you for your help. Meanwhile, i have another question. Does the Loki client support custom labels to write logs?I need to write logs by custom labels at present.
@huzitao yes, you could use a global labels. They would append to every log entries from configured service.
ILogger logger = new LoggerConfiguration()
.WriteTo.GrafanaLoki(
"http://localhost:3100",
labels: new [] { new LokiLabel { Key = "app", Value = "payment"}})
.CreateLogger();
You could find all options in project wiki
This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue.
Dear author: I’d like to know that how to use serilog.loki to establish a customizing client to make an index for writing logs as Elasticsearch.