Saturday, 16 September 2017

Serilog for .net applicationa

1. Modern structure login is a concept of  instead of writing plan text  in log we can write properties of object.

2. So we can use these properties to quires the information about the logs

3. We can integrate these logs to Kibana or Splunk and we can query. using these properties we can create dashboards.

Technical Information  

1. We can integrate serilog using Nuget package to application.
   
     Serilog
     Serilog.Extensions.Logging
     Serilog.Settings.Configuration
     Serilog.Sink.Literal
     Serilog.Sink.Trace


2.  Configure Serilog and write log

    public static class LogingConfiguration
    {
        public static void BuildLogger()
        {
            Log.Logger = new LoggerConfiguration()
                .Enrich.FromLogContext()
                .WriteTo.RollingFile("C:\\Logs\\StromeDashboardLogs.txt")
                .WriteTo.Console(new JsonFormatter())
                .WriteTo.Trace()
                .CreateLogger();
        }
    }

        protected void Application_Start()
        {
         
            LogingConfiguration.BuildLogger();
            Log.Logger.Information("StormDashboard application started");
        }

No comments:

Post a Comment