// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, IApplicationLifetime lifetime, IConfiguration configuration) { //app.UseExceptionHandler(p => //{ //}); app.UseAuthentication();//注意添加这一句,启用验证 if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } app.UseMiddleware(typeof(ExceptionHandlerMiddleWare)); //注册consul //app.RegisterConsul(lifetime, null, configuration); var test = configuration.GetValue <string>("test"); var config = new LoggingConfiguration(); var configTarget = new ExceptionlessTarget() { ApiKey = "ovG91wLK5RWZ8CUSMbYZgUQbhAQZfpIntQ9v8BKz", Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}", ServerUrl = "http://localhost:50000", Name = "Sheepdata", OptimizeBufferReuse = false, }; config.AddTarget(configTarget); //config.AddRuleForAllLevels(configTarget); NLog.Web.NLogBuilder.ConfigureNLog(config); loggerFactory.AddNLog(); app.UseHttpsRedirection(); app.UseMvc(); // Enable middleware to serve generated Swagger as a JSON endpoint. app.UseSwagger(); // Enable middleware to serve swagger-ui (HTML, JS, CSS, etc.), // specifying the Swagger JSON endpoint. app.UseSwaggerUI(c => { c.SwaggerEndpoint("/swagger/v1/swagger.json", "My API V1"); }); }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } else { app.UseHsts(); } //ExceptionlessClient.Default.Configuration.ApiKey = Configuration.GetSection("Exceptionless:ApiKey").Value; //ExceptionlessClient.Default.Configuration.ServerUrl = Configuration.GetSection("Exceptionless:ServerUrl").Value; var config = new LoggingConfiguration(); var configTarget = new ExceptionlessTarget() { ApiKey = "ovG91wLK5RWZ8CUSMbYZgUQbhAQZfpIntQ9v8BKz", Layout = @"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}", ServerUrl = "http://*****:*****@"${date:format=HH\:mm\:ss} ${level} ${message} ${exception}" //}; loggerFactory.AddNLog(); Exceptionless.ExceptionlessClient.Default.Configuration.ApiKey = "ovG91wLK5RWZ8CUSMbYZgUQbhAQZfpIntQ9v8BKz"; Exceptionless.ExceptionlessClient.Default.Configuration.ServerUrl = "http://localhost:50000"; app.UseHttpsRedirection(); app.UseMvc(); }
public static void Main(string[] args) { Console.CursorVisible = false; if (!Console.IsInputRedirected) { StartDisplayingLogMessages(); } ExceptionlessClient.Default.Configuration.AddPlugin <SystemUptimePlugin>(); ExceptionlessClient.Default.Configuration.UseFolderStorage("store"); ExceptionlessClient.Default.Configuration.UseLogger(_log); ExceptionlessClient.Default.Startup(); if (ExceptionlessClient.Default.Configuration.Settings.GetBoolean("EnableWelcomeMessage", false)) { Console.WriteLine($"Hello {Environment.MachineName}!"); } // Test NLog var config = new LoggingConfiguration(); var exceptionlessTarget = new ExceptionlessTarget(); config.AddTarget("exceptionless", exceptionlessTarget); config.LoggingRules.Add(new LoggingRule("*", global::NLog.LogLevel.Debug, exceptionlessTarget)); LogManager.Configuration = config; var logger = LogManager.GetCurrentClassLogger(); logger.Warn() .Message("App Starting...") .Tag("Tag1", "Tag2") .Property("LocalProp", "LocalValue") .Property("Order", new { Total = 15 }) .Write(); // This is how you could log the same message using the fluent api directly. //ExceptionlessClient.Default.CreateLog(typeof(Program).Name, "App Starting...", LogLevel.Info) // .AddTags("Tag1", "Tag2") // .SetProperty("LocalProp", "LocalValue") // .SetProperty("Order", new { Total = 15 }) // .Submit(); #if NET45 // Test log4net XmlConfigurator.Configure(); GlobalContext.Properties["GlobalProp"] = "GlobalValue"; ThreadContext.Properties["LocalProp"] = "LocalValue"; //_log4net.Info("Hi"); #endif var tokenSource = new CancellationTokenSource(); CancellationToken token = tokenSource.Token; ExceptionlessClient.Default.Configuration.AddPlugin(ctx => ctx.Event.Data[RandomData.GetWord()] = RandomData.GetWord()); ExceptionlessClient.Default.Configuration.AddPlugin(ctx => { // use server settings to see if we should include this data if (ctx.Client.Configuration.Settings.GetBoolean("IncludeConditionalData", true)) { ctx.Event.AddObject(new { Total = 32.34, ItemCount = 2, Email = "*****@*****.**" }, "ConditionalData"); } }); ExceptionlessClient.Default.Configuration.Settings.Changed += (sender, changedArgs) => Trace.WriteLine($"Action: {changedArgs.Action} Key: {changedArgs.Item.Key} Value: {changedArgs.Item.Value}"); WriteOptionsMenu(); while (true) { Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 1); var keyInfo = Console.IsInputRedirected ? GetKeyFromRedirectedConsole() : Console.ReadKey(true); if (keyInfo.Key == ConsoleKey.D1) { SendEvent(); } else if (keyInfo.Key == ConsoleKey.D2) { SendContinuousEvents(50, token, 100); } else if (keyInfo.Key == ConsoleKey.D3) { SendContinuousEvents(_delays[_delayIndex], token); } else if (keyInfo.Key == ConsoleKey.D4) { ExceptionlessClient.Default.SubmitSessionStart(); } else if (keyInfo.Key == ConsoleKey.D5) { ExceptionlessClient.Default.Configuration.UseSessions(false, null, true); ExceptionlessClient.Default.SubmitSessionStart(); } else if (keyInfo.Key == ConsoleKey.D6) { SendContinuousEvents(250, token, ev: new Event { Type = Event.KnownTypes.Log, Source = "SampleConsole.Program.Main", Message = "Sample console application event" }); } else if (keyInfo.Key == ConsoleKey.D7) { ExceptionlessClient.Default.SubmitSessionEnd(); } else if (keyInfo.Key == ConsoleKey.D8) { ExceptionlessClient.Default.Configuration.SetUserIdentity(Guid.NewGuid().ToString("N")); } else if (keyInfo.Key == ConsoleKey.P) { Console.SetCursorPosition(0, OPTIONS_MENU_LINE_COUNT + 2); Console.WriteLine("Telling client to process the queue..."); ExceptionlessClient.Default.ProcessQueue(); ClearOutputLines(); } else if (keyInfo.Key == ConsoleKey.F) { SendAllCapturedEventsFromDisk(); ClearOutputLines(); } else if (keyInfo.Key == ConsoleKey.D) { _dateSpanIndex++; if (_dateSpanIndex == _dateSpans.Length) { _dateSpanIndex = 0; } WriteOptionsMenu(); } else if (keyInfo.Key == ConsoleKey.T) { _delayIndex++; if (_delayIndex == _delays.Length) { _delayIndex = 0; } WriteOptionsMenu(); } else if (keyInfo.Key == ConsoleKey.Q) { break; } else if (keyInfo.Key == ConsoleKey.S) { tokenSource.Cancel(); tokenSource = new CancellationTokenSource(); token = tokenSource.Token; ClearOutputLines(); } } }