1- using System ;
2- using System . Collections . Generic ;
31using System . Globalization ;
4- using System . IO ;
5- using System . Linq ;
62using System . Runtime . Serialization ;
73using System . Runtime . Versioning ;
8- using System . Windows . Forms ;
94
105using ColumnizerLib ;
116
@@ -23,8 +18,8 @@ public class Log4jXmlColumnizer : ILogLineXmlColumnizer, IColumnizerConfigurator
2318 public const int COLUMN_COUNT = 9 ;
2419 protected const string DATETIME_FORMAT = "dd.MM.yyyy HH:mm:ss.fff" ;
2520
26- private static readonly XmlConfig xmlConfig = new ( ) ;
27- private const char separatorChar = '\xFFFD ' ;
21+ private static readonly XmlConfig _xmlConfig = new ( ) ;
22+ private const char SEPARATOR_CHAR = '\xFFFD ' ;
2823 private readonly char [ ] trimChars = [ '\xFFFD ' ] ;
2924 private Log4jXmlColumnizerConfig _config ;
3025 private readonly CultureInfo _cultureInfo = new ( "de-DE" ) ;
@@ -45,14 +40,14 @@ public Log4jXmlColumnizer ()
4540
4641 public IXmlLogConfiguration GetXmlLogConfiguration ( )
4742 {
48- return xmlConfig ;
43+ return _xmlConfig ;
4944 }
5045
5146 public ILogLine GetLineTextForClipboard ( ILogLine logLine , ILogLineColumnizerCallback callback )
5247 {
5348 Log4JLogLine line = new ( )
5449 {
55- FullLine = logLine . FullLine . Replace ( separatorChar , '|' ) ,
50+ FullLine = logLine . FullLine . Replace ( SEPARATOR_CHAR , '|' ) ,
5651 LineNumber = logLine . LineNumber
5752 } ;
5853
@@ -81,8 +76,10 @@ public string[] GetColumnNames ()
8176
8277 public IColumnizedLogLine SplitLine ( ILogLineColumnizerCallback callback , ILogLine line )
8378 {
84- ColumnizedLogLine clogLine = new ( ) ;
85- clogLine . LogLine = line ;
79+ ColumnizedLogLine clogLine = new ( )
80+ {
81+ LogLine = line
82+ } ;
8683
8784 var columns = Column . CreateColumns ( COLUMN_COUNT , clogLine ) ;
8885
@@ -103,7 +100,7 @@ public IColumnizedLogLine SplitLine (ILogLineColumnizerCallback callback, ILogLi
103100 columns [ 8 ] . FullValue = line . FullLine ;
104101 }
105102
106- var newDate = dateTime . ToString ( DATETIME_FORMAT ) ;
103+ var newDate = dateTime . ToString ( DATETIME_FORMAT , CultureInfo . InvariantCulture ) ;
107104 columns [ 0 ] . FullValue = newDate ;
108105 }
109106 catch ( Exception )
@@ -118,14 +115,14 @@ public IColumnizedLogLine SplitLine (ILogLineColumnizerCallback callback, ILogLi
118115
119116 if ( cols . Length != COLUMN_COUNT )
120117 {
121- columns [ 0 ] . FullValue = "" ;
122- columns [ 1 ] . FullValue = "" ;
123- columns [ 2 ] . FullValue = "" ;
124- columns [ 3 ] . FullValue = "" ;
125- columns [ 4 ] . FullValue = "" ;
126- columns [ 5 ] . FullValue = "" ;
127- columns [ 6 ] . FullValue = "" ;
128- columns [ 7 ] . FullValue = "" ;
118+ columns [ 0 ] . FullValue = string . Empty ;
119+ columns [ 1 ] . FullValue = string . Empty ;
120+ columns [ 2 ] . FullValue = string . Empty ;
121+ columns [ 3 ] . FullValue = string . Empty ;
122+ columns [ 4 ] . FullValue = string . Empty ;
123+ columns [ 5 ] . FullValue = string . Empty ;
124+ columns [ 6 ] . FullValue = string . Empty ;
125+ columns [ 7 ] . FullValue = string . Empty ;
129126 columns [ 8 ] . FullValue = line . FullLine ;
130127 }
131128 else
@@ -143,11 +140,9 @@ public IColumnizedLogLine SplitLine (ILogLineColumnizerCallback callback, ILogLi
143140
144141 clogLine . ColumnValues = filteredColumns . Select ( a => a as IColumn ) . ToArray ( ) ;
145142
146-
147143 return clogLine ;
148144 }
149145
150-
151146 public bool IsTimeshiftImplemented ( )
152147 {
153148 return true ;
@@ -170,14 +165,14 @@ public DateTime GetTimestamp (ILogLineColumnizerCallback callback, ILogLine line
170165 return DateTime . MinValue ;
171166 }
172167
173- var endIndex = line . FullLine . IndexOf ( separatorChar , 1 ) ;
168+ var endIndex = line . FullLine . IndexOf ( SEPARATOR_CHAR , 1 ) ;
174169
175- if ( endIndex > 20 || endIndex < 0 )
170+ if ( endIndex is > 20 or < 0 )
176171 {
177172 return DateTime . MinValue ;
178173 }
179174
180- var value = line . FullLine . Substring ( 0 , endIndex ) ;
175+ var value = line . FullLine [ .. endIndex ] ;
181176
182177 try
183178 {
@@ -240,9 +235,9 @@ public void Configure (ILogLineColumnizerCallback callback, string configDir)
240235
241236 public void LoadConfig ( string configDir )
242237 {
243- var configPath = configDir + Path . DirectorySeparatorChar + "log4jxmlcolumnizer.json" ;
238+ var configPath = Path . Join ( configDir , "log4jxmlcolumnizer.json" ) ;
244239
245- FileInfo fileInfo = new ( configDir + Path . DirectorySeparatorChar + "log4jxmlcolumnizer.json" ) ;
240+ FileInfo fileInfo = new ( configPath ) ;
246241
247242 if ( ! File . Exists ( configPath ) )
248243 {
@@ -252,15 +247,16 @@ public void LoadConfig (string configDir)
252247 {
253248 try
254249 {
255- _config = JsonConvert . DeserializeObject < Log4jXmlColumnizerConfig > ( File . ReadAllText ( $ "{ fileInfo . FullName } ") ) ;
250+ _config = JsonConvert . DeserializeObject < Log4jXmlColumnizerConfig > ( File . ReadAllText ( fileInfo . FullName ) ) ;
251+
256252 if ( _config . ColumnList . Count < COLUMN_COUNT )
257253 {
258254 _config = new Log4jXmlColumnizerConfig ( GetAllColumnNames ( ) ) ;
259255 }
260256 }
261257 catch ( SerializationException e )
262258 {
263- MessageBox . Show ( e . Message , "Deserialize" ) ;
259+ _ = MessageBox . Show ( e . Message , "Deserialize" ) ;
264260 _config = new Log4jXmlColumnizerConfig ( GetAllColumnNames ( ) ) ;
265261 }
266262 }
@@ -308,7 +304,6 @@ private Column[] MapColumns (Column[] cols)
308304 index ++ ;
309305 }
310306
311-
312307 return [ .. output ] ;
313308 }
314309
0 commit comments