@@ -83,6 +83,8 @@ public Logger(string id, string name, Severity severity = Severity.Info, Diction
8383 public void SetLevel ( Severity maxSeverity ) {
8484 logLevel = maxSeverity ;
8585 }
86+ public bool SetTarget ( string nameOf , bool enabled ) {
87+ Targets . Set ( nameOf , Targets . Get ( nameOf ) . enabled =
8688 /// <summary>
8789 /// Returns the ANSI color corresponding to the severity.
8890 /// </summary>
@@ -113,13 +115,12 @@ public static string GetColor(Severity severity) {
113115 /// <param name="severity">The severity of the text.</param>
114116 /// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
115117 public void Log < T > ( Severity severity , T ? text ) {
116- if ( ( ( byte ) severity ) > ( ( byte ) logLevel ) ) { return ; }
117- string time = DateTime . Now . ToString ( ) ;
118- if ( options . shouldWriteToTerminal ) {
119- Out . WriteLine ( GetColor ( severity ) + "[" + Name + "][" + time + "][" + ANSI . Styles . Bold + severity . ToString ( ) + ANSI . Styles . ResetBold + "]: " + text ? . ToString ( ) + ANSI . Styles . ResetAll ) ;
120- }
121- if ( options . shouldWriteToFile && FileOut != null ) {
122-
118+ if ( ( ( byte ) severity ) > ( ( byte ) logLevel ) ) { return ;
119+ DateTime time = DateTime . Now ;
120+ foreach ( ( ITarget target , bool enabled ) target in Targets ) {
121+ if ( target . enabled ) {
122+ target . target . Write ( severity , time , this , text ) ;
123+ }
123124 }
124125 }
125126 /// <summary>
@@ -179,11 +180,13 @@ public void LogTrace<T>(T? text) {
179180 Log ( Severity . Trace , text ) ;
180181 }
181182 /// <summary>
182- /// Closes / saves the log file , and unregisters this logger.
183+ /// Disposes all targets , and unregisters this logger.
183184 /// </summary>
184185 public void Dispose ( ) {
185186 Loggers . UnRegister ( this ) ;
186- FileOut ? . Close ( ) ;
187+ foreach ( ( ITarget target , bool enabled ) target in Targets ) {
188+ target . target . Dispose ( ) ;
189+ }
187190 GC . SuppressFinalize ( this ) ;
188191 }
189192}
@@ -198,19 +201,21 @@ public interface ITarget : IDisposable {
198201 /// <typeparam name="T">The type of the text.</typeparam>
199202 /// <param name="severity">The severity of the message.</param>
200203 /// <param name="time">The time when it has been logged.</param>
201- /// <param name="name">The name of the logger.</param>
202- /// <param name="ID">The ID of the logger.</param>
204+ /// <param name="logger">The logger.</param>
203205 /// <param name="text">The text to write (<see cref="object.ToString"/>).</param>
204- public void Write < T > ( Severity severity , DateTime time , string name , string ID , T ? text ) ;
206+ public void Write < T > ( Severity severity , DateTime time , Logger logger , T ? text ) ;
205207}
206- public class TerminalTarget : ITarget
207- {
208+ public class TerminalTarget : ITarget {
209+ public TextWriter Out ;
210+ public TerminalTarget ( TextWriter ? terminalOut = null ) {
211+ Out = ( terminalOut ?? Terminal . Out ) ;
212+ }
208213 public void Dispose ( ) {
209214 GC . SuppressFinalize ( this ) ;
210215 }
211216
212217 public void Write < T > ( Severity severity , DateTime time , string name , string ID , T ? text ) {
213-
218+ Out . WriteLine ( Logger . GetColor ( severity ) + "[" + Name + "][" + time . ToString ( ) + "][" + ANSI . Styles . Bold + severity . ToString ( ) + ANSI . Styles . ResetBold + "]: " + text ? . ToString ( ) + ANSI . Styles . ResetAll ) ;
214219 }
215220}
216221public class FileTarget : ITarget
0 commit comments