Skip to content

Commit 1565ab8

Browse files
committed
测试时,测一下异常的输出效果
1 parent 26d2356 commit 1565ab8

File tree

1 file changed

+55
-0
lines changed

1 file changed

+55
-0
lines changed

samples/LoggerSample.MainApp/Program.cs

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System;
22
using System.Diagnostics;
3+
using System.Runtime.CompilerServices;
34
using System.Threading;
45
using System.Threading.Tasks;
56
using DotNetCampus.Logging;
@@ -40,6 +41,41 @@ public static void Main(string[] args)
4041
Log.Error("Error log");
4142
Log.Fatal("Fatal log");
4243

44+
Log.Trace("""
45+
This is a very very long trace log
46+
written in multiline.
47+
""");
48+
Log.Debug("""
49+
This is a very very long debug log
50+
written in multiline.
51+
""");
52+
Log.Info("""
53+
This is a very very long information log
54+
written in multiline.
55+
""");
56+
Log.Warn("""
57+
This is a very very long warning log
58+
written in multiline.
59+
""");
60+
Log.Error("""
61+
This is a very very long error log
62+
written in multiline.
63+
""");
64+
Log.Fatal("""
65+
This is a very very long critical log
66+
written in multiline.
67+
""");
68+
Log.Fatal("""
69+
This is a very very long critical log
70+
written in multiline.
71+
""");
72+
73+
var exception = GetException();
74+
Log.Warn("Ah..., exception!", exception);
75+
Log.Error("Ah..., exception!", exception);
76+
Log.Fatal("Ah..., exception!", exception);
77+
Log.Fatal("Ah..., exception!", exception);
78+
4379
Run();
4480
Thread.Sleep(5000);
4581
}
@@ -55,6 +91,25 @@ private static void Run()
5591
});
5692
Log.Info($"[TEST] 完成 {stopwatch.ElapsedMilliseconds}ms");
5793
}
94+
95+
[MethodImpl(MethodImplOptions.NoInlining)]
96+
private static Exception GetException()
97+
{
98+
try
99+
{
100+
return ThrowException();
101+
}
102+
catch (Exception ex)
103+
{
104+
return ex;
105+
}
106+
}
107+
108+
[MethodImpl(MethodImplOptions.NoInlining)]
109+
private static Exception ThrowException()
110+
{
111+
throw new InvalidOperationException();
112+
}
58113
}
59114

60115
[ImportLoggerBridge<global::LoggerSample.LoggerIndependentLibrary.Logging.ILoggerBridge>]

0 commit comments

Comments
 (0)