Analogy-LogViewer / Analogy.LogViewer.Serilog

Serilog Parser for Analogy Log Viewer
MIT License
56 stars 17 forks source link

How to configure "Analogy.LogViewer.Serilog.Sinks"? #308

Open afluegge opened 3 years ago

afluegge commented 3 years ago

Hi Lior,

I tried to use the log viewer with the self hosted gRPC server together with the Serilog sink. I am not able to get it to work. I have a .NET5 WPF application and I configure my Serilog sinks from the appsettings.json file. For both "Console" and "Debug" sinks everything works fine. However, I am not able to get the "Analogy.LogViewer.Serilog.Sinks" sink to work. I was not able to find any documentation that describes how to setup the sink correctly so that I can see log entries in your log viewer app.

Can you please provide me some guidance on how to setup the following configuration:

What is the correct syntax to configure the sink from appsettings.json? This is my try:

    "Serilog": {
        "WriteTo": [
            {
                "Name": "Debug",
                "Args": {
                    "outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Level:u}][{SourceContext}] {Message:lj}{NewLine}{Exception}"
                }
            },
            {
                "Name": "AnalogyLogServerSink",
                "Args": {
                    "outputTemplate": "[{Timestamp:HH:mm:ss.fff} {Level:u}][{SourceContext}] {Message:lj}{NewLine}{Exception}"
                }
            },
            {
                "Name": "Console",
                "Args": {
                    "outputTemplate": "{Timestamp:yyyy-MM-dd HH:mm:ss} {MachineName} {EnvironmentUserName} [{Level:u4}] <{ThreadId}> [{SourceContext:l}] {Message:lj}{NewLine}{Exception}"
                },
                "theme": "AnsiConsoleTheme.Literate"
            }
        ],
        "Enrich": [
            "FromLogContext",
            "WithMachineName",
            "WithThreadId",
            "WithEnvironmentUserName",
            "WithCorrelationId"
        ],
        "MinimumLevel": {
            "Default": "Verbose"
        }
    }
LiorBanai commented 3 years ago

Hi @afluegge , I'll create demo application and instruction how to use it this weekend :) I have not tested it for some time (I using other extensions like https://github.com/Analogy-LogViewer/Analogy.AspNetCore.LogProvider) so it is possible something might be broken.

Will update you :)

for now you of course can open Serilog logs directly

LiorBanai commented 3 years ago

one quick check, are you using the gRPC Receiver tab? image

LiorBanai commented 3 years ago

yeah the self hosted does not receive the messages. Will update (the Analogy Server (https://github.com/Analogy-LogViewer/Real-Time-Log-Server) works ok)

LiorBanai commented 3 years ago

found the issue (hard coded port 7000) . Once I corrected it the self hosted got messages. I'll update you once everything is fixed :) https://github.com/Analogy-LogViewer/Analogy.LogViewer.gRPC/issues/137

LiorBanai commented 3 years ago

related issue: [Analogy.LogViewer.Serilog.Sinks] Sink is using port 6000 without ability to change address #309

afluegge commented 3 years ago

Could you also please provide documentation on how to configure the serilog sink via appsettings.json?

LiorBanai commented 3 years ago

I have released new version of Analogy with the removal of the hard coded ports. I tested it and it works. to use open the self hosted settings and set your desired port: image

to use the sink:

            var log = new LoggerConfiguration()
                .WriteTo.AnalogyLogServerSink("http://localhost:7000").CreateLogger();
            for (int i = 0; i < 1000; i++)
            {
                log.Information("test {i}", i);
                await Task.Delay(250);
            }

I'm still trying to figure up how to set it in the appsettings.json. no luck for now