24
24
#endregion
25
25
26
26
using System ;
27
+ using System . Diagnostics ;
27
28
using System . Globalization ;
28
29
using System . IO ;
29
30
using System . IO . Compression ;
@@ -36,43 +37,35 @@ namespace BridgeVs.Logging
36
37
public static class Log
37
38
{
38
39
private static string _applicationName ;
39
- private static readonly string LocalApplicationData =
40
- Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
40
+ private static readonly string LocalApplicationData = Environment . GetFolderPath ( Environment . SpecialFolder . LocalApplicationData ) ;
41
41
42
- private static readonly MailAddress MailAddressFrom = new MailAddress ( "[email protected] " , "No Reply Log" ) ;
43
- private static string _logGzipFileName ;
44
-
45
- private static string _moduleName ;
46
42
private static string _logsDir ;
47
43
private static string _logTxtFilePath ;
48
- private static SmtpClient _smtpClient ;
49
44
50
- public static void Configure ( string applicationName , string moduleName , SmtpClient smtpClient = null )
45
+ [ Conditional ( "DEBUG" ) ]
46
+ public static void Configure ( string applicationName , string moduleName )
51
47
{
52
48
if ( string . IsNullOrEmpty ( applicationName ) )
53
49
throw new ArgumentNullException ( nameof ( applicationName ) , "Name of the application must not be null!" ) ;
54
50
55
51
_applicationName = applicationName ;
56
- _moduleName = moduleName ;
57
52
58
- var logTxtFileName = string . Concat ( moduleName , ".txt" ) ;
53
+ string logTxtFileName = string . Concat ( moduleName , ".txt" ) ;
59
54
60
- _logGzipFileName = string . Concat ( _applicationName , ".gz" ) ;
61
55
_logsDir = Path . Combine ( LocalApplicationData , _applicationName ) ;
62
56
63
57
_logTxtFilePath = Path . Combine ( _logsDir , logTxtFileName ) ;
64
-
65
- _smtpClient = smtpClient ;
66
58
}
67
59
60
+ [ Conditional ( "DEBUG" ) ]
68
61
public static void Write ( Exception ex , string context = null )
69
62
{
70
63
try
71
64
{
72
- var text = string . Concat ( ex . GetType ( ) . Name , ": " , ex . Message , "\r \n " , ex . StackTrace ?? "" ) ;
65
+ string text = string . Concat ( ex . GetType ( ) . Name , ": " , ex . Message , "\r \n " , ex . StackTrace ?? "" ) ;
73
66
if ( ex . InnerException != null )
74
67
{
75
- var text2 = text ;
68
+ string text2 = text ;
76
69
text = string . Concat ( text2 , "\r \n INNER: " , ex . InnerException . GetType ( ) . Name , ex . InnerException . Message , ( ex . InnerException . StackTrace ?? "" ) . Replace ( "\n " , "\n " ) ) ;
77
70
}
78
71
if ( ! string . IsNullOrEmpty ( context ) )
@@ -88,16 +81,17 @@ public static void Write(Exception ex, string context = null)
88
81
}
89
82
}
90
83
84
+ [ Conditional ( "DEBUG" ) ]
91
85
private static void InternalWrite ( string msg , params object [ ] args )
92
86
{
93
87
94
88
if ( ! Directory . Exists ( _logsDir ) )
95
89
{
96
90
try
97
91
{
98
- var sec = new DirectorySecurity ( ) ;
92
+ DirectorySecurity sec = new DirectorySecurity ( ) ;
99
93
// Using this instead of the "Everyone" string means we work on non-English systems.
100
- var everyone = new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) ;
94
+ SecurityIdentifier everyone = new SecurityIdentifier ( WellKnownSidType . WorldSid , null ) ;
101
95
sec . AddAccessRule ( new FileSystemAccessRule ( everyone , FileSystemRights . Modify | FileSystemRights . Synchronize , InheritanceFlags . ContainerInherit | InheritanceFlags . ObjectInherit , PropagationFlags . None , AccessControlType . Allow ) ) ;
102
96
Directory . CreateDirectory ( _logsDir , sec ) ;
103
97
}
@@ -127,6 +121,7 @@ private static void InternalWrite(string msg, params object[] args)
127
121
/// <param name="msg">A composite format string (see Remarks) that contains text intermixed with zero or more format items, which correspond to objects in the <paramref name="args"/> array.</param><param name="args">An object array that contains zero or more objects to format. </param>
128
122
129
123
124
+ [ Conditional ( "DEBUG" ) ]
130
125
public static void Write ( string msg , params object [ ] args )
131
126
{
132
127
if ( string . IsNullOrEmpty ( _applicationName ) )
@@ -144,6 +139,7 @@ public static void Write(string msg, params object[] args)
144
139
}
145
140
}
146
141
142
+ [ Conditional ( "DEBUG" ) ]
147
143
public static void WriteIf ( bool condition , string msg , params object [ ] args )
148
144
{
149
145
if ( ! condition ) return ;
0 commit comments