2424#endregion
2525
2626using System ;
27+ using System . Diagnostics ;
2728using System . Globalization ;
2829using System . IO ;
2930using System . IO . Compression ;
@@ -36,43 +37,35 @@ namespace BridgeVs.Logging
3637 public static class Log
3738 {
3839 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 ) ;
4141
42- private static readonly MailAddress MailAddressFrom = new MailAddress ( "linqbridgevs@gmail.com" , "No Reply Log" ) ;
43- private static string _logGzipFileName ;
44-
45- private static string _moduleName ;
4642 private static string _logsDir ;
4743 private static string _logTxtFilePath ;
48- private static SmtpClient _smtpClient ;
4944
50- public static void Configure ( string applicationName , string moduleName , SmtpClient smtpClient = null )
45+ [ Conditional ( "DEBUG" ) ]
46+ public static void Configure ( string applicationName , string moduleName )
5147 {
5248 if ( string . IsNullOrEmpty ( applicationName ) )
5349 throw new ArgumentNullException ( nameof ( applicationName ) , "Name of the application must not be null!" ) ;
5450
5551 _applicationName = applicationName ;
56- _moduleName = moduleName ;
5752
58- var logTxtFileName = string . Concat ( moduleName , ".txt" ) ;
53+ string logTxtFileName = string . Concat ( moduleName , ".txt" ) ;
5954
60- _logGzipFileName = string . Concat ( _applicationName , ".gz" ) ;
6155 _logsDir = Path . Combine ( LocalApplicationData , _applicationName ) ;
6256
6357 _logTxtFilePath = Path . Combine ( _logsDir , logTxtFileName ) ;
64-
65- _smtpClient = smtpClient ;
6658 }
6759
60+ [ Conditional ( "DEBUG" ) ]
6861 public static void Write ( Exception ex , string context = null )
6962 {
7063 try
7164 {
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 ?? "" ) ;
7366 if ( ex . InnerException != null )
7467 {
75- var text2 = text ;
68+ string text2 = text ;
7669 text = string . Concat ( text2 , "\r \n INNER: " , ex . InnerException . GetType ( ) . Name , ex . InnerException . Message , ( ex . InnerException . StackTrace ?? "" ) . Replace ( "\n " , "\n " ) ) ;
7770 }
7871 if ( ! string . IsNullOrEmpty ( context ) )
@@ -88,16 +81,17 @@ public static void Write(Exception ex, string context = null)
8881 }
8982 }
9083
84+ [ Conditional ( "DEBUG" ) ]
9185 private static void InternalWrite ( string msg , params object [ ] args )
9286 {
9387
9488 if ( ! Directory . Exists ( _logsDir ) )
9589 {
9690 try
9791 {
98- var sec = new DirectorySecurity ( ) ;
92+ DirectorySecurity sec = new DirectorySecurity ( ) ;
9993 // 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 ) ;
10195 sec . AddAccessRule ( new FileSystemAccessRule ( everyone , FileSystemRights . Modify | FileSystemRights . Synchronize , InheritanceFlags . ContainerInherit | InheritanceFlags . ObjectInherit , PropagationFlags . None , AccessControlType . Allow ) ) ;
10296 Directory . CreateDirectory ( _logsDir , sec ) ;
10397 }
@@ -127,6 +121,7 @@ private static void InternalWrite(string msg, params object[] args)
127121 /// <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>
128122
129123
124+ [ Conditional ( "DEBUG" ) ]
130125 public static void Write ( string msg , params object [ ] args )
131126 {
132127 if ( string . IsNullOrEmpty ( _applicationName ) )
@@ -144,6 +139,7 @@ public static void Write(string msg, params object[] args)
144139 }
145140 }
146141
142+ [ Conditional ( "DEBUG" ) ]
147143 public static void WriteIf ( bool condition , string msg , params object [ ] args )
148144 {
149145 if ( ! condition ) return ;
0 commit comments