[TestMethod()] public void MultipleFilters() { var Logger = new LoggerProxy(Log); var filters = Logger.Filters; filters.Add(LogFilters.AddPrefix("Pre>")); Log.WriteDelay = 0; Log.Filters.Add(LogFilters.IgnoreDuplicateExceptions()); Log.Filters.Add(LogFilters.AutoMultiParam); Log.Filters.Add(LogFilters.FormatParams); Log.Filters.Add(LogFilters.ResolveLazy); Log.Filters.Add(LogFilters.AddPostfix("<Post")); Logger.Info("ARST"); Assert.IsTrue(LogContent.Contains("Pre>ARST"), "Simple Log"); Logger.Info("A", "R", null, "S", "T"); Assert.IsTrue(LogContent.Contains(">A R null S T<"), "Format multi params"); Logger.Info((Func <string>)(() => "QWFP")); Assert.IsTrue(LogContent.Contains(">QWFP"), "Resolve lazy"); Exception subject = new Exception(); Logger.Error(subject); Assert.IsTrue(LogContent.Contains("Pre>System.Exception:"), "Exception is logged"); var len = LogSize; Logger.Error("Error: {0}", subject); Assert.IsTrue(LogSize == len, "Duplicate is suppressed"); }
} // ctor public void Log(LoggerProxy log, string firstLine) { // logging log.Info(String.Join(Environment.NewLine, firstLine, " Filename: {0}", " Originator: {1}", " VirtualFileName: {2}", " Stamp: {3:F}", " Format: {4}", " MaximumRecordSize: {5:N0}", " FileSize: {6:N0}", " FileSizeUnpacked: {7:N0}", " Description: {8}" ), fileInfo.Name, sourceOrDestination, virtualFileName, fileStamp, format, maximumRecordSize, fileSize, fileSizeUnpacked, description ); } // proc Log
public FileServiceSession(DirectoryFileServiceItem service, int sessionId) { this.sessionId = sessionId; this.service = service; this.log = LoggerProxy.Create(service.Log, sessionId.ToString()); log.Info("Session started..."); service.OnSessionStart(); } // ctor
protected LuaScript(LuaEngine engine, string scriptId, bool compileWithDebugger) { this.engine = engine; this.log = LoggerProxy.Create(engine.Log, scriptId); this.scriptId = scriptId; this.chunk = null; this.compiledWithDebugger = compileWithDebugger; // attach the script to the engine engine.AddScript(this); log.Info("Hinzugefügt."); } // ctor
} // proc Dispose protected virtual void Dispose(bool disposing) { if (disposing) { foreach (var g in engine.GetAttachedGlobals(scriptId)) { g.ResetScript(); } // Remove the script from the engine engine.RemoveScript(this); log.Info("Entfernt."); Procs.FreeAndNil(ref chunk); } } // proc Dispose
} // func GetScript public void OnScriptChanged() { var e = new CancelEventArgs(!autoRun); if (ScriptChanged != null) { ScriptChanged(this, e); } if (e.Cancel || !IsCompiled) { needToRun = true; log.Info("Waiting for execution."); } else { Run(false); } } // proc OnScriptChanged
[TestMethod()] public void LoggerProxy() { Log.WriteDelay = 1000; var Log2 = new FileLogger("logtest2.tmp", 1000); LoggerProxy proxy = new LoggerProxy(true, Log); proxy.Masters.Add(Log2); proxy.Info("Proxy"); proxy.Flush(); Assert.IsTrue(LogContent.Contains("Proxy"), "Proxy is forwarding to 1st log"); Assert.IsTrue(File.ReadAllText(Log2.LogFile).Contains("Proxy"), "Proxy is forwarding to 2nd log"); proxy.Clear(); Assert.IsFalse(File.Exists(Log.LogFile), "Proxy is clearing 1st Log"); Assert.IsFalse(File.Exists(Log2.LogFile), "Proxy is clearing 2nd Log"); Log2.Level = System.Diagnostics.SourceLevels.Verbose; proxy.Level = System.Diagnostics.SourceLevels.Information; proxy.Verbo("Verbose filtered"); proxy.Flush(); Assert.IsFalse(File.Exists(Log.LogFile), "Proxy is not forwarding low levels"); Assert.IsFalse(File.Exists(Log2.LogFile), "Proxy is not forwarding low levels 2"); proxy.Level = System.Diagnostics.SourceLevels.Verbose; proxy.Verbo("Verbose written"); proxy.Flush(); Assert.IsFalse(File.Exists(Log.LogFile), "Proxy is not writing to low levels"); Assert.IsTrue(File.Exists(Log2.LogFile), "Proxy is writing to low levels 2"); proxy.Clear(); try { new LoggerProxy(false).Clear(); Assert.IsTrue(false, "Proxy failed to disallow clear"); } catch (InvalidOperationException) { Assert.IsTrue(true, "Proxy may disallow clear"); } Assert.AreEqual(null, Error, "OnError"); }
} // proc SendAnswerAsync private void Info(string message) => log.Info(message);
} // ctor public void Dispose() { service.OnSessionClosed(); log.Info("Session finished..."); } // proc Dispose
} // ctor public void Log(LoggerProxy log, string firstLine) { // logging log.Info(String.Join(Environment.NewLine, firstLine, " Filename: {0}", " Originator: {1}", " VirtualFileName: {2}", " Stamp: {3:F}", " Format: {4}", " MaximumRecordSize: {5:N0}", " FileSize: {6:N0}", " FileSizeUnpacked: {7:N0}", " Description: {8}" ), fileInfo.Name, originator, virtualFileName, fileStamp, format, maximumRecordSize, fileSize, fileSizeUnpacked, description ); } // proc Log
public override void NotifyBeginApplication() => log.Info("Begin of application");