File tree 3 files changed +52
-132
lines changed
3 files changed +52
-132
lines changed Original file line number Diff line number Diff line change @@ -60,10 +60,7 @@ public static void RunFunction(HttpListenerContext ctx)
60
60
//var content = new MultipartContent("form-data", contentType.Boundary);
61
61
//var multiData = new MultipartFormDataContent(contentType.Boundary);
62
62
//multiData.
63
- // TODO create job
64
- // ughh.. logging is not going to work as is..
65
- // maybe change IFunction to have an IFunctionContext object with all of the bits attached
66
- // (basically the Job object) and include logging
63
+ TODO create job
67
64
// fs.Write(sep,0,sep.Length);
68
65
// var help = $"{contentType.Name} {contentType.MediaType} {contentType.Boundary}";
69
66
// var ct = Encoding.UTF8.GetBytes(help + "\r\n");
Load Diff This file was deleted.
Original file line number Diff line number Diff line change
1
+ namespace ImageFunctions . Core . Logging ;
2
+
3
+ public sealed class LogToConsole : ICoreLog
4
+ {
5
+ public bool BeVerbose { get ; set ; }
6
+
7
+ public void Message ( string m )
8
+ {
9
+ Console . ResetColor ( ) ;
10
+ Console . WriteLine ( m ) ;
11
+ }
12
+
13
+ public void Info ( string m )
14
+ {
15
+ if ( BeVerbose ) {
16
+ WithColor ( $ "I: { m } ", ConsoleColor . Gray ) ;
17
+ }
18
+ }
19
+
20
+ public void Warning ( string m )
21
+ {
22
+ WithColor ( $ "W: { m } ", ConsoleColor . Yellow , true ) ;
23
+ }
24
+
25
+ public void Error ( string m , Exception e = null )
26
+ {
27
+ string se = e == null ? "" : $ " : { e . Message } ";
28
+ WithColor ( $ "E: { m } { se } ", ConsoleColor . Red , true ) ;
29
+ }
30
+
31
+ public void Debug ( string m )
32
+ {
33
+ #if DEBUG
34
+ WithColor ( $ "D: { m } ", ConsoleColor . DarkGray ) ;
35
+ #endif
36
+ }
37
+
38
+ void WithColor ( string m , ConsoleColor color , bool error = false )
39
+ {
40
+ //using try-finally to make sure the console color gets reset
41
+ // otherwise stopping the program (ctrl-c) can leave the console with a leftover color
42
+ try {
43
+ Console . ForegroundColor = color ;
44
+ var tw = error ? Console . Error : Console . Out ;
45
+ tw . WriteLine ( m ) ;
46
+ }
47
+ finally {
48
+ Console . ResetColor ( ) ;
49
+ }
50
+ }
51
+ }
You can’t perform that action at this time.
0 commit comments