개정판 ce3f0d7a
issue #745: change logger with log4net
Change-Id: I1be08796d6f1a110b7ec3f94121a6bea96fc7b56
KCOM/App.xaml.cs | ||
---|---|---|
53 | 53 |
/// <summary> |
54 | 54 |
/// logger |
55 | 55 |
/// </summary> |
56 |
public static ILog log = null; |
|
56 |
public static ILog DBLogger = null; |
|
57 |
public static ILog FileLogger = null; |
|
57 | 58 |
|
58 | 59 |
/// <summary> |
59 | 60 |
/// Application Data Folder |
... | ... | |
95 | 96 |
} |
96 | 97 |
/// up to here |
97 | 98 |
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException); |
98 |
log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
|
99 |
log = LogManager.GetLogger(typeof(App)); |
|
99 |
log4net.GlobalContext.Properties["LogDBFilePath"] = Path.Combine(AppDataFolder, "log4net.db"); |
|
100 |
log4net.GlobalContext.Properties["LogFilePath"] = Path.Combine(AppDataFolder, "Log", "log4net.log"); |
|
101 |
App.DBLogger = LogManager.GetLogger("DBLogger"); |
|
102 |
App.FileLogger = LogManager.GetLogger("EventLogger"); |
|
100 | 103 |
|
101 | 104 |
splash.Show(false, false); |
102 | 105 |
|
... | ... | |
252 | 255 |
{ |
253 | 256 |
try |
254 | 257 |
{ |
255 |
App.log.Fatal(e.ExceptionObject as Exception);
|
|
258 |
App.DBLogger.Fatal(e.ExceptionObject as Exception);
|
|
256 | 259 |
} |
257 | 260 |
catch (Exception ex) |
258 | 261 |
{ |
... | ... | |
289 | 292 |
|
290 | 293 |
private void ErrorLogFileWrite(string Err) |
291 | 294 |
{ |
295 |
App.FileLogger.Debug(Err); |
|
296 |
/* |
|
292 | 297 |
try |
293 | 298 |
{ |
294 | 299 |
string pathString = AppDataFolder + "\\Err"; |
... | ... | |
306 | 311 |
{ |
307 | 312 |
string strError = er.ToString(); |
308 | 313 |
} |
314 |
*/ |
|
309 | 315 |
} |
310 | 316 |
} |
311 | 317 |
} |
KCOM/Logger.cs | ||
---|---|---|
18 | 18 |
if (lv >= Loglevel) //세팅의 로그 레벨보다 낮거나 같으면 남김 |
19 | 19 |
{ |
20 | 20 |
string Msg = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\t" + "REQ" + "\t" + name + "(" + (string)text + ")" + "\r\n"; |
21 |
string Dir = App.AppDataFolder + "\\Log"; |
|
22 |
|
|
23 |
if (Directory.Exists(Dir) == false) |
|
24 |
{ |
|
25 |
Directory.CreateDirectory(Dir); |
|
26 |
} |
|
27 |
|
|
28 |
int min = DateTime.Now.Minute / 1; |
|
29 |
|
|
30 |
string path = Dir + "/" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd HH-") + min + ".txt"; |
|
31 |
File.AppendAllText(path, Msg); |
|
21 |
App.FileLogger.Debug(Msg); |
|
32 | 22 |
} |
33 | 23 |
} |
34 | 24 |
catch (Exception e) |
... | ... | |
45 | 35 |
if (lv >= Loglevel) //세팅의 로그 레벨보다 낮거나 같으면 남김 |
46 | 36 |
{ |
47 | 37 |
string Msg = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\t" + "RES" + "\t" + name + "(" + (string)text + ")" + "\r\n"; |
48 |
string Dir = App.AppDataFolder + "\\Log"; |
|
49 |
|
|
50 |
if (Directory.Exists(Dir) == false) |
|
51 |
{ |
|
52 |
Directory.CreateDirectory(Dir); |
|
53 |
} |
|
54 |
|
|
55 |
int min = DateTime.Now.Minute / 1; |
|
56 |
|
|
57 |
string path = Dir + "/" + "Log_" + DateTime.Now.ToString("yyyy-MM-dd HH-") + min + ".txt"; |
|
58 |
File.AppendAllText(path, Msg); |
|
38 |
App.FileLogger.Debug(Msg); |
|
59 | 39 |
} |
60 | 40 |
} |
61 | 41 |
catch (Exception e) |
... | ... | |
72 | 52 |
if (lv >= Loglevel) //세팅의 로그 레벨보다 낮거나 같으면 남김 |
73 | 53 |
{ |
74 | 54 |
string Msg = DateTime.Now.ToString("yyyy-MM-dd hh:mm:ss") + "\t" + "RES" + "\t" + text + "\r\n"; |
75 |
string Dir = App.AppDataFolder + "\\Check";
|
|
55 |
string Dir = Path.Combine(App.AppDataFolder, "Check");
|
|
76 | 56 |
|
77 | 57 |
if (Directory.Exists(Dir) == false) |
78 | 58 |
{ |
KCOM/app.config | ||
---|---|---|
18 | 18 |
<appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender"> |
19 | 19 |
<bufferSize value="100" /> |
20 | 20 |
<connectionType value="System.Data.SQLite.SQLiteConnection, System.Data.SQLite" /> |
21 |
<connectionString type="log4net.Util.PatternString" value="Data Source=%property{LogFilePath};Version=3;Synchronous=Off" /> |
|
21 |
<connectionString type="log4net.Util.PatternString" value="Data Source=%property{LogDBFilePath};Version=3;Synchronous=Off" />
|
|
22 | 22 |
<commandText value="INSERT INTO Log (Date, Level, Logger, Message, StackTrace) VALUES (@Date, @Level, @Logger, @Message, @StackTrace)" /> |
23 | 23 |
<parameter> |
24 | 24 |
<parameterName value="@Date" /> |
... | ... | |
54 | 54 |
</layout> |
55 | 55 |
</parameter> |
56 | 56 |
</appender> |
57 |
<appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender"> |
|
58 |
<file type="log4net.Util.PatternString" value="%property{LogFilePath}" /> |
|
59 |
<datePattern value="yyyy-MM-dd.log" /> |
|
60 |
<appendToFile value="true" /> |
|
61 |
<rollingStyle value="Size" /> |
|
62 |
<maximumFileSize value="100KB" /> |
|
63 |
<maxSizeRollBackups value="100" /> |
|
64 |
<!-- Use -1 for unlimited--> |
|
65 |
<staticLogFileName value="true" /> |
|
66 |
<countDirection value="1" /> |
|
67 |
<layout type="log4net.Layout.PatternLayout"> |
|
68 |
<!--<header value="DATE MESSAGE " /> --> |
|
69 |
<param name="ConversionPattern" value="%date %message %newline" /> |
|
70 |
</layout> |
|
71 |
</appender> |
|
57 | 72 |
<root> |
58 | 73 |
<level value="ALL" /> |
59 |
<appender-ref ref="AdoNetAppender" /> |
|
60 | 74 |
</root> |
75 |
<logger name="DBLogger" additivity="false"> |
|
76 |
<level value="ALL" /> |
|
77 |
<appender-ref ref="AdoNetAppender" /> |
|
78 |
</logger> |
|
79 |
<logger name="EventLogger" additivity="false"> |
|
80 |
<level value="ALL" /> |
|
81 |
<appender-ref ref="RollingFileAppender" /> |
|
82 |
</logger> |
|
61 | 83 |
</log4net> |
62 | 84 |
<runtime> |
63 | 85 |
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> |
내보내기 Unified diff