Example #1
0
        public static void Main(string[] args)
        {
            var env = Environment.GetEnvironmentVariable("ASPNETCORE_ENVIRONMENT");

            var config = new ConfigurationBuilder()
                         .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                         .AddJsonFile($"appsettings.{env}.json", optional: true, reloadOnChange: true)
                         .Build();

            // Pegando url de conexão com o Seq
            var seqOptions = new SeqOptions();

            config.GetSection(nameof(SeqOptions)).Bind(seqOptions);

            Log.Logger = new LoggerConfiguration()
                         .MinimumLevel.Debug()
                         .MinimumLevel.Override("Microsoft", LogEventLevel.Information)
                         .Enrich.FromLogContext()
                         .WriteTo.Console()
                         .WriteTo.Seq(seqOptions.Connection)
                         .CreateLogger();

            Log.Information("Application is starting...");
            Log.Information("Seq starting in {seqConn}", seqOptions.Connection);

            CreateHostBuilder(args)
            .Build()
            .MigrateDatabase()
            .Run();
        }
Example #2
0
        static void Main(string[] args)
        {
            LoggerBuilder builder = new LoggerBuilder();

            SeqOptions seqOptions = new SeqOptions
            {
                Enabled = true,
                Url     = "http://localhost:5341"
            };

            Log.Logger = builder
                         .UseSuggestedSetting("RestSharp", "RestSharp.Easy")
                         .SetupSeq(seqOptions)
                         .BuildLogger();

            Log.Logger.Error("TESTE");

            var client = new EasyRestClient("http://pruu.herokuapp.com/dump", requestKey: "12345");

            var body = new { test = "xxx", PersonTest = PersonTest.FirstName };

            var result = client.SendRequestAsync <dynamic>(HttpMethod.Post, "restsharp-easy", body)
                         .GetAwaiter().GetResult();

            var result2 = client.SendRequest <dynamic>(HttpMethod.Post, "restsharp-easy", body);

            Thread.Sleep(5000);
        }
        /// <summary>
        /// Setup seq
        /// </summary>
        /// <param name="options"></param>
        /// <returns></returns>
        public LoggerBuilder SetupSeq(SeqOptions options)
        {
            this.OutputConfiguration.Seq.Options = options
                                                   ?? throw new ArgumentNullException(nameof(options));

            if (string.IsNullOrWhiteSpace(options.Url) == true && options.Enabled == true)
            {
                throw new ArgumentNullException(nameof(options.Url));
            }

            this.OutputConfiguration.Seq.Enabled = options.Enabled;

            return(this);
        }
Example #4
0
        public static void Build_Basics_Logger()
        {
            // arrage
            LoggerBuilder builder = new LoggerBuilder();

            SeqOptions seqOptions = new SeqOptions
            {
                Url    = "http://localhost",
                ApiKey = "123456"
            };

            SplunkOptions splunkOptions = new SplunkOptions
            {
                Url   = "http://localhost",
                Token = "123456",
                Index = "my.index"
            };

            NewRelicOptions newRelicOptions = new NewRelicOptions
            {
                AppName    = "asd",
                LicenseKey = "123"
            };

            DataDogOptions dataDogOptions = new DataDogOptions
            {
                ApiKey  = "123",
                Service = "service",
                Host    = "host",
                Tags    = new string[] { "tags" },
                Source  = "source"
            };

            Log.Logger = builder
                         .UseSuggestedSetting("MyDomain", "MyApplication")
                         .SetupSeq(seqOptions)
                         .SetupSplunk(splunkOptions)
                         .SetupNewRelic(newRelicOptions)
                         .SetupDataDog(dataDogOptions)
                         .BuildLogger();

            // act
            var logger = builder.BuildLogger();

            // assert
            Assert.NotNull(logger);
        }
Example #5
0
        public static void Build_Basics_Logger_With_Json_Formatter()
        {
            // arrage
            LoggerBuilder builder = new LoggerBuilder();

            SeqOptions seqOptions = new SeqOptions
            {
                Url    = "http://localhost",
                ApiKey = "123456"
            };

            var splunkSettings = new SplunkLogSettings();

            splunkSettings.ServerURL = "http://localhost";
            splunkSettings.Token     = "123456";
            splunkSettings.Index     = "my.index";

            SplunkOptions splunkOptions = new SplunkOptions
            {
                Enabled       = true,
                Url           = "http://localhost",
                Token         = "123456",
                Index         = "my.index",
                TextFormatter = new SplunkJsonFormatter(splunkSettings)
            };

            Log.Logger = builder
                         .UseSuggestedSetting("MyDomain", "MyApplication")
                         .SetupSeq(seqOptions)
                         .SetupSplunk(splunkOptions)
                         .BuildLogger();

            // act
            var logger = builder.BuildLogger();

            // assert
            Assert.NotNull(logger);
        }
Example #6
0
 public SeqPublisher(Func <HttpClient> httpClientFactory, SeqOptions options)
 {
     _options           = options ?? throw new ArgumentNullException(nameof(options));
     _httpClientFactory = httpClientFactory ?? throw new ArgumentNullException(nameof(httpClientFactory));
 }