Skip to content

LucaGabi/VSE-Serilog-events-viewer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

15 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

VSE Serilog events viewer

Visual Studio Code Extention to inspect serilog events

This vscode extention allows inspection of logs created with serilog sinks here: https://github.com/serilog/serilog-sinks-mongodb

dotnet add package Serilog.Sinks.MongoDB --version 5.1.1
Install-Package Serilog.Sinks.MongoDB -Version 5.1.1
<PackageReference Include="Serilog.Sinks.MongoDB" Version="5.1.1" />

Features:

  • filter by time frame, level, content
  • filter by expresion (similar to where clause in SQL)
  • persist config file for future inspection
  • shortcuts for fast use:
    • 'f' toggle filter panel
    • 'esc' toggle expression filtering
    • inside expression editor 'ctrl-up' & 'ctrl-down' sets previous or next expression in current session history
    • 'a' move time-frame back
    • 'x' move time-frame forward
    • 'e' filter by level error
    • 'w' filter by level warning
    • 'd' filter by level debug
    • 'i' filter by level info
    • 'q' filter by level info

paypal

Create new connection

Open from existing config

Serilog setup

public class JSSTimeStamp : ILogEventEnricher
{
    static long t70 = new DateTime(1970, 01, 01).ToLocalTime().Ticks;
    static long js7() => (long)TimeSpan.FromTicks(DateTime.Now.ToLocalTime().Ticks - t70).TotalMilliseconds;
    public void Enrich(LogEvent logEvent, ILogEventPropertyFactory propertyFactory)
    {
        logEvent.AddPropertyIfAbsent(new LogEventProperty("ts", new ScalarValue(js7())));
    }
}

....

 var logger = new LoggerConfiguration()
                .MinimumLevel.Debug()
                .Enrich.FromLogContext()
                .Enrich.WithProperty("Origin", "Sample ingest")
                .Enrich.WithAssemblyName()
                .Enrich.WithCorrelationId()
                .Enrich.WithMemoryUsage()
                .Enrich.WithProcessId()
                .Enrich.WithThreadId()
                .Enrich.With<JSSTimeStamp>()
                .WriteTo.Conditional(_ => true, wt => wt.Console())
                .WriteTo.MongoDBBson(cfg =>
                {
                    // custom MongoDb configuration
                    //var mongoDbSettings = new MongoClientSettings
                    //{
                    //    UseTls = false,
                    //    AllowInsecureTls = true,
                    //    Credential = MongoCredential.CreateCredential("DBNAME", "USER", "PASSWORD"),
                    //    Server = new MongoServerAddress("127.0.0.1",27017)
                    //};

                    var mongoDbInstance = new MongoClient(
                        "mongodb://USER:[email protected]:27017/")
                    .GetDatabase("DBNAME");

                    // sink will use the IMongoDatabase instance provided
                    cfg.SetMongoDatabase(mongoDbInstance);
                })
                .CreateLogger();

Generate fake logs

Inside fake-logs-producer\seqcli-dev\src\Roastery\Program.cs change these lines (24,25):

private const string ConnectionString = "...";
private const string DB = "...";

About

Visual Studio Code Extention to inspect serilog events

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published