static void Main(string[] args) { try { //var configBuilder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) // .AddXmlFile("App.Config", true, true); var config = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddXmlFile("App.Config", true, true).Build(); LOGGER.Initialize(config).RunsOnConsole() .AddExceptionless() .AllDone(); var logger = LOGGER.GetLogger <Program>(mode: LogEventSendMode.Manually); logger.LogInformation("测试1", ctx => ctx.ForExceptionless(h => h.AddTags("CosmosLogging"))); logger.LogInformation("测试2", builder => builder.AddTags("CosmosLogging")); logger.LogError("world"); logger.SubmitLogger(); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole(o => o.EnableDisplayCallerInfo(ThreeValuedBoolean.False).EnableDisplayEventIdInfo(true)) .AddSampleLog(s => s.UseMinimumLevel(LogEventLevel.Error).EnableDisplayCallerInfo(true)) .AddExceptionsIntegration() .AllDone(); var logger = LOGGER.GetLogger <Program>(); var inner = new ArgumentNullException("test", "Inner exception"); var exception = new InvalidOperationException("Invalid operation exception for test.", inner); logger.LogError(exception, @" Gets exception '{$Exception:U:N}' Inner exception '{$Exception:U:U/N}' Type: {$Exception::type} Message: {$Exception} Inner Message: {$Exception::unwrap/M} Detail: {$Exception:j:D}"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
// ReSharper disable once UnusedParameter.Local static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole() .AddNLog(s => s.UseMinimumLevel(LogEventLevel.Information).UseDefaultConfigFile()) .AddExceptionless(s => s.UseMinimumLevel(LogEventLevel.Information).UseAppSettings()) .AddSampleLog(s => s.UseMinimumLevel(LogEventLevel.Information)) .AllDone(); var logger = LOGGER.GetLogger <Program>(LogEventLevel.Verbose, mode: LogEventSendMode.Manually); logger.LogInformation("hello"); logger.LogError("world"); logger.SubmitLogger(); var logger2 = LOGGER.GetLogger <Program>(LogEventLevel.Verbose); logger2.LogInformation("submit log automatically"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
static void Main(string[] args) { try { var builder = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()); LOGGER.Initialize(builder).RunsOnConsole() .AddLog4Net(s => s.UseDefaultOriginConfigFilePath()) .AllDone(); var logger = LOGGER.GetLogger <Program>(mode: LogEventSendMode.Manually); logger.LogInformation("hello"); logger.LogError("world"); logger.SubmitLogger(); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
public ActionResult Index() { var logger = LOGGER.GetLogger <HomeController>(); logger.LogFatal("Error:)"); return(View()); }
static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole(o => o.EnableDisplayCallerInfo(ThreeValuedBoolean.False).EnableDisplayEventIdInfo(true)) .AddSampleLog(s => s.UseMinimumLevel(LogEventLevel.Error).EnableDisplayCallerInfo(true)) .AllDone(); var logger = LOGGER.GetLogger <Program>(mode: LogEventSendMode.Manually); logger.LogInformation("hello"); logger.LogInformation("hello {0},number={1}", new { A = "1" }, 2); logger.LogError("world", ctx => ctx.SetTags("Alex").SetTags("Lewis")); logger.LogError("Nice {@L}", ctx => ctx.SetParameter(new { L = "KK" })); logger.SubmitLogger(); var future = logger.ToFuture(); //future logger api style 1 future .SetLevel(LogEventLevel.Information) .SetMessage("future log===> Nice {@L}") .SetTags("Alex", "Lewis") .SetParameter(new { L = "KK2" }) .SetException(new ArgumentNullException(nameof(args))) .Submit(); //future logger api style 2 future.UseFields( Fields.Level(LogEventLevel.Information), Fields.Message("future log===> Nice {@L}"), Fields.Tags("Alex", "Lewis"), Fields.Args(new { L = "KK3" }), Fields.Exception(new ArgumentNullException(nameof(args)))).Submit(); var simple = logger.ToSimple(); simple.LogInformation("Write log by simple logger"); simple.LogError(new ArgumentException(), "Write log with exception for {0}", "Alex LEWIS"); simple.LogInformation("Write log by simple logger{{helloworld}}{$NewLine}"); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole(o => o.EnableDisplayCallerInfo(ThreeValuedBoolean.False).EnableDisplayEventIdInfo(true)) .AddFilelog(s => s .UseMinimumLevel(LogEventLevel.Error) .AddStrategy("GeneralStrategy", @"x\logs\file.log", rollingInterval: RollingInterval.Minute)) .AllDone(); var logger = LOGGER.GetLogger <Program>(); logger.LogInformation("hello"); logger.LogError("world", ctx => ctx.SetTags("Alex").SetTags("Lewis")); logger.LogError("Nice {@L}", ctx => ctx.SetParameter(new { L = "KK" })); //logger.SubmitLogger(); Thread.Sleep(TimeSpan.FromMinutes(1)); var future = logger.ToFuture(); //future logger api style 1 future .SetLevel(LogEventLevel.Information) .SetMessage("future log===> Nice {@L}") .SetTags("Alex", "Lewis") .SetParameter(new { L = "KK2" }) .SetException(new ArgumentNullException(nameof(args))) .Submit(); //future logger api style 2 future.UseFields( Fields.Level(LogEventLevel.Information), Fields.Message("future log===> Nice {@L}"), Fields.Tags("Alex", "Lewis"), Fields.Args(new { L = "KK3" }), Fields.Exception(new ArgumentNullException(nameof(args)))).Submit(); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
// ReSharper disable once UnusedParameter.Local static void Main(string[] args) { try { var root = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true, true).Build(); LOGGER.Initialize(root).RunsOnConsole().AddNLog().AddSampleLog().AllDone(); // LOGGER.Initialize("appsettings.json", FileTypes.Json).RunsOnConsole().AddNLog().AddSampleLog().AllDone(); var logger1 = LOGGER.GetLogger <Program>(mode: LogEventSendMode.Manually); logger1.LogWarning("hello, {$Date} {$MachineName}"); logger1.SubmitLogger(); // // var logger2 = LOGGER.GetLogger<Program>(); // logger2.LogWarning("world"); // // var logger3 = LOGGER.GetLogger<Program>().ToFuture(); // var logger4 = logger2.ToFuture(); // // var logger5 = FUTURE.GetFutureLogger<Program>(); // logger5.SetLevel(LogEventLevel.Warning) // .SetMessage("future log===> Nice {@L}") // .SetTags("Alex", "Lewis") // .SetParameter(new {L = "KK2"}) // .SetException(new ArgumentNullException(nameof(args))) // .Submit(); // // logger5.UseFields( // Fields.Level(LogEventLevel.Warning), // Fields.Message("future log===> Nice {@L}"), // Fields.Tags("Alex", "Lewis"), // Fields.Args(new {L = "KK3"}), // Fields.Exception(new ArgumentNullException(nameof(args)))).Submit(); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole() .AddSampleLog() .AllDone(); var logger = LOGGER.GetLogger <Program>(); logger.LogInformation("hello world!"); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
// ReSharper disable once UnusedParameter.Local static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole() .AddNLog() .AddSampleLog(s => s.UseMinimumLevel(LogEventLevel.Debug)) .AllDone(); var logger = LOGGER.GetLogger <Program>(mode: LogEventSendMode.Manually); logger.LogInformation("hello"); logger.LogError("world"); logger.SubmitLogger(); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
static void Main(string[] args) { try { LOGGER.Initialize().RunsOnConsole(o => o.EnableDisplayCallerInfo(ThreeValuedBoolean.False).EnableDisplayEventIdInfo(true)) .AddSampleLog(s => s.UseMinimumLevel(LogEventLevel.Error).EnableDisplayCallerInfo(true)) .AllDone(); var logger = LOGGER.GetLogger <Program>(mode: LogEventSendMode.Manually); logger.LogInformation("hello"); logger.LogInformation("hello {0},number={1}", new { A = "1" }, 2); logger.LogError("world", ctx => ctx.SetTags("Alex").SetTags("Lewis")); logger.LogError("Nice {@L}", ctx => ctx.SetParameter(new { L = "KK" })); logger.SubmitLogger(); var logger2 = LOGGER.GetLogger <Program>(LogEventSendMode.Manually); logger2.LogInformation("hello level, length=完整000: {$Level}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=井号001: {$Level:#}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=井号002: {$Level:##}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=井号003: {$Level:###}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=井号004: {$Level:####}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=井号011: {$Level:###########}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=命令001: {$Level::length=1}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=命令002: {$Level::length=2}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=命令003: {$Level::length=3}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=命令004: {$Level::length=4}"); logger2.SubmitLogger(); logger2.LogInformation("hello level, length=命令011: {$Level::length=11}"); logger2.SubmitLogger(); using (var scope = logger.BeginScope("OK")) { } var future = logger.ToFuture(); //future logger api style 1 future .SetLevel(LogEventLevel.Information) .SetMessage("future log ====> Nice {@L} ====> [{$EventIdChains}][{$EventId}][{$EventName}][{$BizTraceId}]") .SetTags("Alex", "Lewis") .SetParameter(new { L = "KK2" }) .SetTrackInfo("1234567890", "TrackTest", "biz123") .SetException(new ArgumentNullException(nameof(args))) .Submit(); //future logger api style 2 future.UseFields( Fields.Level(LogEventLevel.Information), Fields.Message("future log===> Nice {@L}"), Fields.Tags("Alex", "Lewis"), Fields.Args(new { L = "KK3" }), Fields.Exception(new ArgumentNullException(nameof(args)))).Submit(); var simple = logger.ToSimple(); simple.LogInformation("Write log by simple logger"); simple.LogError(new ArgumentException(), "Write log with exception for {0}", "Alex LEWIS"); simple.LogInformation("Write log by simple logger{{helloworld}}{$NewLine}"); Console.WriteLine("Hello World!"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
static void Main(string[] args) { try { var root = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory()) .AddJsonFile("appsettings.json", true, true).Build(); LOGGER.Initialize(root).RunsOnConsole() .PreheatMessageTemplates(Preheater) .AddSampleLog(s => s.UseMinimumLevel(LogEventLevel.Information)) .AllDone(); var logger = LOGGER.GetLogger <Program>(); // lock (SyncLock) { // //Text token // logger.Information("text token test--> {{1.helloworld"); // logger.Information("text token test--> {{2.helloworld}"); // logger.Information("text token test--> {{3.helloworld}}"); // logger.Information("text token test--> {{4.helloworld}lewis"); // logger.Information("text token test--> {{5.helloworld}lewis"); // logger.Information("text token test--> {{6.helloworld}}lewis"); // } // // lock (SyncLock) { // //format token for $ // logger.Information("$ format test--> {$01.TokenBody"); // logger.Information("$ format test--> {$02.TokenBody:"); // logger.Information("$ format test--> {$03.TokenBody}"); // logger.Information("$ format test--> {$04.TokenBody:}"); // logger.Information("$ format test--> {$05.TokenBody "); // logger.Information("$ format test--> {$06.TokenBody"); // logger.Information("$ format test--> {$07.TokenBody:Format"); // logger.Information("$ format test--> {$08.TokenBody:Format:"); // logger.Information("$ format test--> {$09.TokenBody:Format}"); // logger.Information("$ format test--> {$10.TokenBody:Format:}"); // logger.Information("$ format test--> {$11.TokenBody other text"); // logger.Information("$ format test--> {$12.TokenBody}other text"); // logger.Information("$ format test--> {$13.TokenBody: other text"); // logger.Information("$ format test--> {$14.TokenBody:}other text"); // logger.Information("$ format test--> {$15.TokenBody:Format other text"); // logger.Information("$ format test--> {$16.TokenBody:Format}other text"); // logger.Information("$ format test--> {$17.TokenBody:Format: other text"); // logger.Information("$ format test--> {$18.TokenBody:Format:}other text"); // } // // lock (SyncLock) { // //params token for $ // logger.Information("$ params test--> {$19.TokenBody:Format:params"); // logger.Information("$ params test--> {$20.TokenBody:Format:params:"); // logger.Information("$ params test--> {$21.TokenBody:Format:params}"); // logger.Information("$ params test--> {$22.TokenBody:Format:params:}"); // logger.Information("$ params test--> {$23.TokenBody:Format:params other text"); // logger.Information("$ params test--> {$24.TokenBody:Format:params}other text"); // logger.Information("$ params test--> {$25.TokenBody:Format:params: other text"); // logger.Information("$ params test--> {$26.TokenBody:Format:params:}other text"); // } // // lock (SyncLock) { // //format token for @ // logger.Information("@ format test--> {@101.TokenBody"); // logger.Information("@ format test--> {@102.TokenBody:"); // logger.Information("@ format test--> {@103.TokenBody}"); // logger.Information("@ format test--> {@104.TokenBody:}"); // logger.Information("@ format test--> {@105.TokenBody "); // logger.Information("@ format test--> {@106.TokenBody"); // logger.Information("@ format test--> {@107.TokenBody:Format"); // logger.Information("@ format test--> {@108.TokenBody:Format:"); // logger.Information("@ format test--> {@109.TokenBody:Format}"); // logger.Information("@ format test--> {@110.TokenBody:Format:}"); // logger.Information("@ format test--> {@111.TokenBody other text"); // logger.Information("@ format test--> {@112.TokenBody}other text"); // logger.Information("@ format test--> {@113.TokenBody: other text"); // logger.Information("@ format test--> {@114.TokenBody:}other text"); // logger.Information("@ format test--> {@115.TokenBody:Format other text"); // logger.Information("@ format test--> {@116.TokenBody:Format}other text"); // logger.Information("@ format test--> {@117.TokenBody:Format: other text"); // logger.Information("@ format test--> {@118.TokenBody:Format:}other text"); // } // // lock (SyncLock) { // //params token for @ // logger.Information("@ params test--> {@119.TokenBody:Format:params"); // logger.Information("@ params test--> {@120.TokenBody:Format:params:"); // logger.Information("@ params test--> {@121.TokenBody:Format:params}"); // logger.Information("@ params test--> {@122.TokenBody:Format:params:}"); // logger.Information("@ params test--> {@123.TokenBody:Format:params other text"); // logger.Information("@ params test--> {@124.TokenBody:Format:params}other text"); // logger.Information("@ params test--> {@125.TokenBody:Format:params: other text"); // logger.Information("@ params test--> {@126.TokenBody:Format:params:}other text"); // } // // logger.Information("token test--> {{alexLEWIS} }.}}..{$123}.{$123WithSpace ...{$456:000}.{$789:111:333}nice{@999}{{$12333}"); // logger.Information("token test--> alexLEWIS {$1234567890:"); // logger.Information("token test--> {$789:111:3[ ]33}"); // logger.Information("token test--> forerunner {$ErrorToken:ErrorFormat:ErrorParams"); // logger.LogInformation(@" // //Google、{{AWS}}和{@Azure}都已经发表了声明,{$ConsoleHelloWorld:jpr30w},说道: //“我们的云(基本上)已经打好了补丁,现在轮到你们为虚拟机操作系统打补丁了”。 //遗憾的是,对于为什么要同{时}对虚拟机管理程序和虚拟机操作系统打补丁,他们没有提供多少细节。 //安全研究人员Katie Moussouris援引了Robert O'Callahan博文中的一段话:{$Memeda , //“对于CPU供应商和云供应商而言,重要的是准确地说明他们采取了什么防范措施, //什么攻击他们无法防范以及他们期望下游客户负责解决哪些问题”。 //AWS在声明中明确表示,“我们会保障客户的实例不会受到来自其他实例的威胁”。 //这意味着,VM操作系统仍然需要打补丁来防止App之间的攻击或者对特定VM内核的攻击, //来自{$Amazon:yyyyMMdd[ ]HH[:]mm[:]ss}的Richard Harvey对此进行了确认。 // //"); // logger.LogInformation("position test{10}"); // logger.LogInformation("position test{10} "); // logger.LogInformation("position test{10:}"); // logger.LogInformation("position test{10:} "); // logger.LogInformation("position test{10::}"); // logger.LogInformation("position test{10::} "); // logger.LogInformation("position test{10:w}"); // logger.LogInformation("position test{10:w:} "); logger.LogInformation("{$Date::yyyy年MM月dd日} token test: {@Hello:U}, {0:U}, {@World},{1}, {$ConsoleHelloWorld}, {$Hello}, {@Alewix}, {3}", new Args(new { Hello = "_hello_" }, "?world?")); logger.LogInformation("token test: {@Hello}, {0}, {@World}?????", new Args(new { Hello = "_hello_", World = "_world_" }, "?world?")); using (var scope = logger.BeginScope("123")) { logger.LogInformation("token test: {@Hello}, {0}, {@World}"); } Console.WriteLine("I'm live"); } catch (Exception e) { Console.WriteLine(e.Message); Console.WriteLine(e.Source); Console.WriteLine(e.StackTrace); } Console.ReadLine(); }
public void Process() { var logger = LOGGER.GetLogger <Program>(); logger.LogInformation("hello"); }