//Next log message id = 30 static Logger() { traceSource = new TraceSource("mss"); FileLogTraceListener logListener = new FileLogTraceListener(); logListener.BaseFileName = "mss-log"; logListener.CustomLocation = MssFileSystemLocations.SettingsFolder; logListener.AutoFlush = true; logListener.MaxFileSize = 5000000; //5MB logListener.Delimiter = " | "; logListener.LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly; logListener.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages; logListener.TraceOutputOptions = TraceOptions.ThreadId; TextWriterTraceListener logWriterListener = new TextWriterTraceListener(MssFileSystemLocations.SettingsFolder + "log.txt"); traceSource.Listeners.Add(logListener); traceSource.Switch = new SourceSwitch("switch", ""); //TODO: this should probably be loaded from the registry or a settings file. traceSource.Switch.Level = SourceLevels.Warning; //Remove log files from previous weeks foreach (string logFilePath in Directory.GetFiles(MssFileSystemLocations.SettingsFolder, logListener.BaseFileName + "*.log")) { if (logFilePath != logListener.FullLogFileName) { File.Delete(logFilePath); } } }
protected FileLogTraceListener GetWriter() { if (_writer != null) { return(_writer); } lock (Locker) { if (_writer == null) { var path = GetFilePath(); var dirPath = System.IO.Path.GetDirectoryName(path); var rootFileName = System.IO.Path.GetFileNameWithoutExtension(path); var writer = new FileLogTraceListener() { Location = LogFileLocation.Custom, CustomLocation = dirPath, BaseFileName = rootFileName, MaxFileSize = GetMaxFileSize(), AutoFlush = true, LogFileCreationSchedule = LogFileCreationScheduleOption.Daily }; _writer = writer; } } return(_writer); }
// Initialize our logging support for stranded elements found. Output is sent to the daily log file // StrandedFound-YYYY-MM-DD.log created (or updated) in the same folder where Stranded.exe resides. // Returns true if logging was successfully initialized, false otherwise. Exception caught and logged in // %LOCALAPPDATA%\AcTools\Logs\Stranded-YYYY-MM-DD.log on initialization failure. private static bool initStrandedFoundLogging() { bool ret = false; // assume failure try { TraceSource ts = new TraceSource("Stranded"); // this program name _tl = (FileLogTraceListener)ts.Listeners["StrandedFound"]; _tl.Location = LogFileLocation.ExecutableDirectory; // create the log file in the same folder as our executable _tl.BaseFileName = "StrandedFound"; // our log file name begins with this name _tl.MaxFileSize = 83886080; // log file can grow to a maximum of 80 megabytes in size _tl.ReserveDiskSpace = 2500000000; // at least 2.3GB free disk space must exist for logging to continue // append -YYYY-MM-DD to the log file name // additional runs of this app in the same day append to this file (by default) _tl.LogFileCreationSchedule = LogFileCreationScheduleOption.Daily; _tl.AutoFlush = true; // true to make sure we capture data in the event of an exception ret = true; } catch (Exception exc) { AcDebug.Log($"Exception caught and logged in Program.initStrandedFoundLogging{Environment.NewLine}{exc.Message}"); } return(ret); }
private void setLogFileListenerFilter(FileLogTraceListener listener) { #if DEBUG listener.Filter = new EventTypeFilter(LogFileFilterLevel.MostVerbose(SourceLevels.Information)); #else listener.Filter = new EventTypeFilter(LogFileFilterLevel); #endif }
public void DiskSpaceTest3() { using (FileLogTraceListener log = new FileLogTraceListener()) { log.Location = LogFileLocation.TempDirectory; log.MaxFileSize = 1000; log.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.ThrowException; log.Write(new string('z', 1001)); } }
public void DiskSpaceTest1() { using (FileLogTraceListener log = new FileLogTraceListener()) { log.Location = LogFileLocation.TempDirectory; log.ReserveDiskSpace = new System.IO.DriveInfo(log.FullLogFileName [0].ToString()).TotalFreeSpace; log.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.ThrowException; log.WriteLine("TestLine"); } }
public static void ConfigureLogging(string logsDir, LogContext context, int maxRolledFiles) { if (!_loggingConfigured) { // Init trace sources specific to the browser or render context // that is currently running. _logDirectory = Environment.ExpandEnvironmentVariables(logsDir); _pid = Process.GetCurrentProcess().Id.ToString(CultureInfo.InvariantCulture).PadLeft(5); // Max file size for log files is 10MB (the default is 5MB if not explicitly set). const int maxFileSize = 10 * 1024 * 1024; switch (context) { case LogContext.Browser: CleanupCefLog(); // Write default trace source messages to a paragon log file. _paragonTraceListener = new FileLogTraceListener { AutoFlush = true, Location = LogFileLocation.Custom, CustomLocation = _logDirectory, LogFileCreationSchedule = LogFileCreationScheduleOption.Daily, BaseFileName = "paragon", DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages, MaxFileSize = maxFileSize }; ParagonTraceSources.Default.Listeners.Add(_paragonTraceListener); CleanupLogFiles(_logDirectory, maxRolledFiles, "paragon", "application-*"); break; case LogContext.Renderer: _rendererTraceListener = new FileLogTraceListener { AutoFlush = true, Location = LogFileLocation.Custom, CustomLocation = _logDirectory, LogFileCreationSchedule = LogFileCreationScheduleOption.Daily, BaseFileName = "renderer", DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages, MaxFileSize = maxFileSize }; // Write default trace source messages to a renderer log file. ParagonTraceSources.Default.Listeners.Add(_rendererTraceListener); CleanupLogFiles(_logDirectory, maxRolledFiles, "renderer"); break; } _loggingConfigured = true; } }
private void disposeResources() { disposeConfigFileWatcher(); traceAction($"{nameof(LogFileFactory)} Is Being Reset ..."); TraceSources.RemoveSelector(this); lock (SyncLock) { logFileListener?.Dispose(); logFileListener = null; } }
public LognLM(string section, NCCConfig.Config cfg, int pid) { FileLogTraceListener listener = null; ts = new TraceSource(section); try { foreach (TraceListener item in ts.Listeners) { // every file logger points to the same file and has the same attributes, they are really a merged logger set (for now, until we need something else) if (item is FileLogTraceListener) { listener = (FileLogTraceListener)item; listener.BaseFileName = String.Format("NCC6[{0,4}]", pid); // add thread id here listener.Append = true; listener.AutoFlush = false; // dev note: expose a setter for this property, to set true for critical passages if (!NCCConfig.Config.isDefaultPath(cfg.App.RootLoc)) { listener.Location = LogFileLocation.Custom; listener.CustomLocation = cfg.App.LogFilePath; } listener.MaxFileSize = cfg.App.RolloverSizeMB * 1024 * 1024; // logdetails cmd line flag crudely enables this option set, only because the App.Config sharedListeners and switch source sections do not permit setting this attribute. if (cfg.App.isSet(NCCConfig.NCCFlags.logDetails)) { item.TraceOutputOptions |= cfg.App.LoggingDetailOptions; } if (string.IsNullOrEmpty(CurrentLogFilePath)) { CurrentLogFilePath = listener.FullLogFileName; //System.IO.Path.Combine(listener.CustomLocation, listener.BaseFileName + DateTime.Now.ToString("yyyy-MM-dd") + ".log"); } } else { // item.TraceOutputOptions |= (TraceOptions.DateTime | TraceOptions.ThreadId); } } } catch (Exception e) { Console.WriteLine(e.Message); } if (cfg.App.IsLevelSet()) // use the cmd line or UI override, if one is present, { // test: but if the internal switch value was higher as set in app.config, this assignment is either overridden later or has no effect on the pre-constructed switches if (ts != null) { ts.Switch.Level = cfg.App.Level(); } } }
/// <summary> /// Initialize application logging support, for general purpose or error messages, in conjunction /// with a client application's <tt>\<prog_name\>.exe.config</tt> file and Log(string, bool). /// </summary> /// <remarks>Creates weekly <a href="https://msdn.microsoft.com/en-us/library/microsoft.visualbasic.logging.filelogtracelistener(v=vs.110).aspx">log files</a> /// in <tt>\%LOCALAPPDATA\%\\AcTools\\Logs</tt> in the format <tt>\<prog_name\>-YYYY-MM-DD.log</tt> with the first day /// of the current week in the file name. The \c AcTools\\Logs folder is created if not already there. Log files can grow /// to a maximum of 80MB in size. At least 2.3GB free space must exist for logging to continue. Additional log files are /// created with an iteration part (blue circle) should a write conflict occur:</remarks> /*! \htmlonly * <img src="LogFileIteration.png"/> * \endhtmlonly */ /// <returns>\e true if logging support successfully initialized, \e false on error.</returns> /// <exception cref="Exception">caught on failure to handle a range of exceptions with error sent to STDOUT.</exception> /*! \par Example usage: */ /*! \code * // Init our logging support so we can log errors. * string error; * if (!AcDebug.initAcLogging()) * { * MessageBox.Show(error, "PromoHist", MessageBoxButtons.OK, MessageBoxIcon.Stop); * return; * } * \endcode */ /*! \par XML that must exist in \<\e prog_name\>.exe.config. Change \e source \e name attribute to \<\e prog_name\>. */ /*! \code * <system.diagnostics> * <assert assertuienabled="false"/> * <sources> * <source name="PromoHist"> <!-- name attribute value must be program executable's root name --> * <listeners> * <remove name="Default" /> * <add name="AcLog" type="Microsoft.VisualBasic.Logging.FileLogTraceListener, Microsoft.VisualBasic, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" /> * </listeners> * </source> * </sources> * </system.diagnostics> * \endcode */ public static bool initAcLogging() { bool ret = false; // assume failure try { // Get root name of our executable for initializing our TraceSource object below. // This name must be specified in the application's .config file for logging to work. string exeRootName = String.Empty; using (Process currentProcess = Process.GetCurrentProcess()) { ProcessModule pm = currentProcess.MainModule; string module = pm.ModuleName; exeRootName = Path.GetFileNameWithoutExtension(module); } string localappdata = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData); string logsFolder = Path.Combine(localappdata, "AcTools\\Logs"); if (!Directory.Exists(logsFolder)) { Directory.CreateDirectory(logsFolder); } TraceSource ts = new TraceSource(exeRootName); _log = (FileLogTraceListener)ts.Listeners["AcLog"]; _log.Location = LogFileLocation.Custom; _log.CustomLocation = logsFolder; // our log file name begins with this name _log.BaseFileName = exeRootName; // allow log files to grow up to 40 megabytes in size //_log.MaxFileSize = 41943040; // allow log files to grow up to 80 megabytes in size _log.MaxFileSize = 83886080; // at least 2.3GB free disk space must exist for logging to continue _log.ReserveDiskSpace = 2500000000; // use the first day of the current week in the log file name _log.LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly; // true to make sure we capture data in the event of an exception _log.AutoFlush = true; ret = true; } catch (Exception exc) { Console.WriteLine($"Exception caught in AcDebug.initAcLogging{Environment.NewLine}{exc.Message}"); } return(ret); }
public void Write() { var cache = new TraceEventCache(); var listener = new FileLogTraceListener(); listener.Location = LogFileLocation.Custom; listener.CustomLocation = GetTestFilePath(); listener.Write("Write"); listener.WriteLine("WriteLine"); listener.TraceEvent(eventCache: cache, source: "Source", eventType: TraceEventType.Warning, id: 3, message: "TraceEvent"); listener.TraceData(eventCache: cache, source: "Source", eventType: TraceEventType.Error, id: 4, data: "TraceData"); listener.Flush(); listener.Close(); }
/// <summary> /// This method must construct the <see cref="LogFileListener"/>, using the /// <see cref="GetLogFolderPath"/>, <see cref="GetLogFileName"/>, and /// <see cref="LogFileFilterLevel"/>. This implementation then sets: /// <see cref="FileLogTraceListener.Append"/> false, /// <see cref="LogFileCreationScheduleOption.Daily"/>, and /// <see cref="TraceOptions.DateTime"/>. /// </summary> /// <returns>Not null.</returns> protected virtual FileLogTraceListener CreateFileLogTraceListener() { FileLogTraceListener result = new FileLogTraceListener(GetLogFileName()) { Location = LogFileLocation.Custom, BaseFileName = GetLogFileName(), CustomLocation = GetLogFolderPath(), Append = false, LogFileCreationSchedule = LogFileCreationScheduleOption.Daily, TraceOutputOptions = TraceOptions.DateTime, }; setLogFileListenerFilter(result); return(result); }
public void AppendTest() { using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); log.Append = false; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Assert.AreEqual("nunit\tCritical\t0\t\r\n", data, "#01"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); log.Append = true; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Assert.AreEqual("nunit\tCritical\t0\t\r\n" + "nunit\tCritical\t0\t\r\n", data, "#02"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); log.Append = false; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Assert.AreEqual("nunit\tCritical\t0\t\r\n", data, "#03"); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); } }
public void AppendTest() { using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); log.Append = false; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Assert.AreEqual ("nunit\tCritical\t0\t\r\n", data, "#01"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); log.Append = true; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Assert.AreEqual ("nunit\tCritical\t0\t\r\n" + "nunit\tCritical\t0\t\r\n", data, "#02"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); log.Append = false; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Assert.AreEqual ("nunit\tCritical\t0\t\r\n", data, "#03"); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); } }
public void Properties() { var listener = new FileLogTraceListener(); _ = listener.Location; _ = listener.AutoFlush; _ = listener.IncludeHostName; _ = listener.Append; _ = listener.DiskSpaceExhaustedBehavior; _ = listener.BaseFileName; _ = listener.FullLogFileName; _ = listener.LogFileCreationSchedule; _ = listener.MaxFileSize; _ = listener.ReserveDiskSpace; _ = listener.Delimiter; _ = listener.Encoding; _ = listener.CustomLocation; }
private static void SetTraceListener() { System.Diagnostics.Trace.Listeners.Remove("LogWriter"); Process process = System.Diagnostics.Process.GetCurrentProcess(); _Category = process.ProcessName; m_ProcessID = process.Id; // If asked, we'll initialize with a process specific file name. BooleanSwitch tsUniqueLog = new BooleanSwitch("UniqueLog", "Generate separate log for each process instance"); if (tsUniqueLog.Enabled && string.IsNullOrEmpty(_OutputFile)) { string path = System.IO.Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "log"); string logName = string.Format("{0}-{1}", _Category, m_ProcessID); FileLogTraceListener myListener = new FileLogTraceListener("LogWriter"); myListener.Location = LogFileLocation.Custom; myListener.Append = true; myListener.BaseFileName = logName; myListener.CustomLocation = path; myListener.LogFileCreationSchedule = LogFileCreationScheduleOption.Daily; System.Diagnostics.Trace.Listeners.Add(myListener); System.Diagnostics.Trace.AutoFlush = true; } else { //指定のファイル名でログを出力 string path = System.IO.Path.Combine(System.AppDomain.CurrentDomain.SetupInformation.ApplicationBase, "log"); if (!System.IO.Directory.Exists(path)) { System.IO.Directory.CreateDirectory(path); } string fullName = System.IO.Path.Combine(path, _OutputFile); if (System.IO.File.Exists(fullName)) { System.IO.File.Delete(fullName); } DefaultTraceListener myListener = new DefaultTraceListener(); myListener.Name = "LogWriter"; myListener.LogFileName = fullName; System.Diagnostics.Trace.Listeners.Add(myListener); System.Diagnostics.Trace.AutoFlush = true; } }
private void setupTracingUnsafe() { bool resetIsInitializing = false; try { lock (SyncLock) { if (!isInitialized || isInitializing) { return; } isInitializing = true; resetIsInitializing = true; } TraceSources.For(TraceFileFactoryAssembly) .Info("Configure tracing."); HandleBeginSetupTracing(); disposeResources(); if (ToggleLogFile) { lock (SyncLock) { logFileListener = CreateFileLogTraceListener(); } } setupConfigFileWatcher(); if (addToTraceSources) { TraceSources.AddSelector(this); } traceAction( LogFileListener != null ? $"{nameof(LogFileFactory)} Trace File Initialized." : $"{nameof(LogFileFactory)} Reset With No Trace File."); } finally { if (resetIsInitializing) { lock (SyncLock) { isInitializing = false; } } } HandleEndSetupTracing(); }
public void Init() { _targetDirectory = Environment.GetEnvironmentVariable("PROJECTK_PACKAGE_CACHE"); if (string.IsNullOrEmpty(_targetDirectory)) { _targetDirectory = @"c:\projectk-cache"; } var fileTraceListener = new FileLogTraceListener { AutoFlush = true, Location = LogFileLocation.Custom, CustomLocation = _targetDirectory, BaseFileName = "ProjectKClone", TraceOutputOptions = TraceOptions.DateTime, LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly }; Trace.Listeners.Add(fileTraceListener); }
public static void AddApplicationTraceListener(string appId) { // Max file size for log files is 10MB (the default is 5MB if not explicitly set). const int maxFileSize = 10 * 1024 * 1024; _appTraceListener = new FileLogTraceListener { AutoFlush = true, Location = LogFileLocation.Custom, CustomLocation = _logDirectory, LogFileCreationSchedule = LogFileCreationScheduleOption.Daily, BaseFileName = "application-" + appId, DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages, MaxFileSize = maxFileSize }; // Write app trace source messages to an application log file. ParagonTraceSources.App.Listeners.Add(_appTraceListener); }
public void DefaultPropertiesTest() { using (FileLogTraceListener log = new FileLogTraceListener()) { Assert.AreEqual(true, log.Append, "A1"); Assert.AreEqual(false, log.AutoFlush, "A2"); Assert.AreEqual(System.IO.Path.GetFileNameWithoutExtension(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName, "B1"); Assert.AreEqual(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.CustomLocation, "C1"); Assert.AreEqual("\t", log.Delimiter, "D1"); Assert.AreEqual(DiskSpaceExhaustedOption.DiscardMessages, log.DiskSpaceExhaustedBehavior, "D2"); Assert.AreEqual(System.Text.Encoding.UTF8.EncodingName, log.Encoding.EncodingName, "E1"); Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "F1"); Assert.IsNull(log.Filter, "F2"); Assert.AreEqual(false, log.IncludeHostName, "I1"); Assert.AreEqual(LogFileLocation.LocalUserApplicationDirectory, log.Location, "L1"); Assert.AreEqual(LogFileCreationScheduleOption.None, log.LogFileCreationSchedule, "L2"); Assert.AreEqual(5000000, log.MaxFileSize, "M1"); Assert.AreEqual("FileLogTraceListener", log.Name, "N1"); Assert.AreEqual(10000000, log.ReserveDiskSpace, "R1"); } }
/// <summary> /// 日志控制器 /// </summary> /// <param name="LogDirectory">日志文件目录</param> /// <param name="LogFileName">日志文件名称前缀</param> public static void CreateLogListener(string LogDirectory, string LogFileName) { LogListener = new FileLogTraceListener("UnityLogListener") { DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.DiscardMessages, LogFileCreationSchedule = LogFileCreationScheduleOption.Daily, Location = LogFileLocation.Custom, MaxFileSize = 100 * 1024 * 1024, CustomLocation = LogDirectory, BaseFileName = LogFileName, Encoding = Encoding.UTF8, IncludeHostName = true, AutoFlush = true, Append = true, IndentSize = 4, }; LogListener.WriteLine("——————————————————————————"); Info("程序启动..."); }
public void DefaultPropertiesTest() { using (FileLogTraceListener log = new FileLogTraceListener ()) { Assert.AreEqual (true, log.Append, "A1"); Assert.AreEqual (false, log.AutoFlush, "A2"); Assert.AreEqual (System.IO.Path.GetFileNameWithoutExtension(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName, "B1"); Assert.AreEqual (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.CustomLocation, "C1"); Assert.AreEqual ("\t", log.Delimiter, "D1"); Assert.AreEqual (DiskSpaceExhaustedOption.DiscardMessages, log.DiskSpaceExhaustedBehavior, "D2"); Assert.AreEqual (System.Text.Encoding.UTF8.EncodingName, log.Encoding.EncodingName, "E1"); Assert.AreEqual (System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "F1"); Assert.IsNull (log.Filter, "F2"); Assert.AreEqual (false, log.IncludeHostName, "I1"); Assert.AreEqual (LogFileLocation.LocalUserApplicationDirectory, log.Location, "L1"); Assert.AreEqual (LogFileCreationScheduleOption.None, log.LogFileCreationSchedule, "L2"); Assert.AreEqual (5000000, log.MaxFileSize, "M1"); Assert.AreEqual ("FileLogTraceListener", log.Name, "N1"); Assert.AreEqual (10000000, log.ReserveDiskSpace, "R1"); } }
/// <summary> /// Constructor /// </summary> public MainWindow() { // make an ACS folder in the AppData folder // uncomment for the final version // Also, change useAppDateFolder in asterics.ini !!! //if ((!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\")) || // (!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\")) || // (!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\"))) { // Directory.CreateDirectory(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\groups\\"); //} //if (!Directory.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\componentcollections\\")) { // Directory.CreateDirectory(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\componentcollections\\"); //} // uncomment for local use if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\groups\\")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\groups\\"); } if (!Directory.Exists(AppDomain.CurrentDomain.BaseDirectory + "\\componentcollections\\")) { Directory.CreateDirectory(AppDomain.CurrentDomain.BaseDirectory + "\\componentcollections\\"); } // loading the asterics.ini file, containing some basic settings // uncomment for the final version /*if (File.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData)+"\\AsTeRICS\\ACS\\asterics.ini")) { ini = new IniFile(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\asterics.ini"); } else */ if (File.Exists(AppDomain.CurrentDomain.BaseDirectory + "asterics.ini")) { ini = new IniFile(AppDomain.CurrentDomain.BaseDirectory + "asterics.ini"); } else { MessageBox.Show(Properties.Resources.IniFileNotFoundText, Properties.Resources.IniFileNotFoundHeader, MessageBoxButton.OK, MessageBoxImage.Error); Application.Current.Shutdown(); } // Setting the localisation info, if no value is set, the system value will be used. // More info about the used localisation technique can be found at: // http://www.codeproject.com/KB/WPF/WPFUsingLocbaml.aspx // Localisation should be done before initializing the components ACS.Properties.Resources.Culture = new System.Globalization.CultureInfo(ini.IniReadValue("Options", "language")); //ACS.Properties.Resources.Culture = new System.Globalization.CultureInfo("de-AT"); // Read local language settings: //ACS.Properties.Resources.Culture = System.Threading.Thread.CurrentThread.CurrentCulture; InitializeComponent(); // Remove the original default trace listener and add a new one (for logging exceptions) traceListener = new FileLogTraceListener(); if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) { traceListener.BaseFileName = Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\ACS"; } else { traceListener.BaseFileName = "ACS"; } traceListener.TraceOutputOptions = TraceOptions.DateTime | TraceOptions.ProcessId | TraceOptions.Callstack; traceListener.LogFileCreationSchedule = LogFileCreationScheduleOption.None; traceListener.CustomLocation = "."; traceListener.AutoFlush = true; traceListener.Append = false; traceListener.Delimiter = "\r\n"; traceListener.Filter = new EventTypeFilter(SourceLevels.Error); traceSource = new TraceSource("mySource"); sourceSwitch = new SourceSwitch("SourceSwitch", "Verbose"); traceSource.Switch = sourceSwitch; traceSource.Listeners.Add(traceListener); this.Closing += MainWindow_Closing; // Adding mouse listeners to the drawing canvas canvas.MouseLeftButtonDown += OnLeftDown; canvas.MouseLeftButtonUp += OnLeftUp; canvas.MouseMove += OnMouseMove; // Context menu for the components componentContextMenu = new ContextMenu(); // Channel related context menu entries componentContextMenuItemAddChannel = new MenuItem(); componentContextMenuItemAddChannel.Header = Properties.Resources.ComponentContextMenuAddChannel; componentContextMenu.Items.Add(componentContextMenuItemAddChannel); componentContextMenuItemConnectChannel = new MenuItem(); componentContextMenuItemConnectChannel.Header = Properties.Resources.ComponentContextMenuConnectChannel; // set inactive componentContextMenuItemAddChannel.IsEnabled = false; // making channels with ontext menu only when context menu is called by keyboard componentContextMenuItemConnectChannel.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemConnectChannel); componentContextMenuItemDropChannel = new MenuItem(); componentContextMenuItemDropChannel.Header = Properties.Resources.ComponentContextMenuDropChannel; componentContextMenuItemDropChannel.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemDropChannel); componentContextMenuItemDropChannel.Click += ComponentContextMenuItemDrop_Click; componentContextMenu.Items.Add(new Separator()); // Event Channel related context menu entries componentContextMenuItemAddEventChannel = new MenuItem(); componentContextMenuItemAddEventChannel.Header = Properties.Resources.ComponentContextMenuAddEventChannel; componentContextMenuItemAddEventChannel.Click += ComponentContextMenuItemAddEvent_Click; componentContextMenu.Items.Add(componentContextMenuItemAddEventChannel); componentContextMenuItemConnectEventChannel = new MenuItem(); componentContextMenuItemConnectEventChannel.Header = Properties.Resources.ComponentContextMenuConnectEventChannel; componentContextMenuItemConnectEventChannel.Click += ComponentContextMenuItemConnectEvent_Click; // set inactive componentContextMenuItemConnectEventChannel.IsEnabled = false; componentContextMenuItemAddEventChannel.IsEnabled = false; // making event channels with ontext menu only when context menu is called by keyboard componentContextMenu.Items.Add(componentContextMenuItemConnectEventChannel); componentContextMenuItemDropEventChannel = new MenuItem(); componentContextMenuItemDropEventChannel.Header = Properties.Resources.ComponentContextMenuDropEventChannel; componentContextMenuItemDropEventChannel.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemDropEventChannel); componentContextMenuItemDropEventChannel.Click += ComponentContextMenuItemDropEvent_Click; componentContextMenu.Items.Add(new Separator()); MenuItem componentContextMenuItemMove = new MenuItem(); componentContextMenuItemMove.Header = Properties.Resources.ComponentContextMenuMoveComponent; componentContextMenuItemMove.Click += ComponentContextMenuItemMove_Click; componentContextMenu.Items.Add(componentContextMenuItemMove); componentContextMenuItemDelete = new MenuItem(); componentContextMenuItemDelete.Header = Properties.Resources.ComponentContextMenuDeleteComponent; componentContextMenuItemDelete.Click += ComponentContextItemDelete_Click; componentContextMenu.Items.Add(componentContextMenuItemDelete); MenuItem componentContextItemProperties = new MenuItem(); componentContextItemProperties.Header = Properties.Resources.ComponentContextMenuComponentProperties; componentContextItemProperties.Click += ComponentContextItemProperties_Click; componentContextMenu.Items.Add(componentContextItemProperties); MenuItem componentContextItemStatus = new MenuItem(); componentContextItemStatus.Header = Properties.Resources.ComponentContextMenuComponentStatus; componentContextItemStatus.Click += ComponentContextItemStatus_Click; componentContextMenu.Items.Add(componentContextItemStatus); componentContextMenuItemSolveConflict = new MenuItem(); componentContextMenuItemSolveConflict.Header = Properties.Resources.ComponentContextMenuRemoveConflict; componentContextMenuItemSolveConflict.Click += ComponentContextItemSolveConflict_Click; componentContextMenuItemSolveConflict.IsEnabled = false; componentContextMenu.Items.Add(componentContextMenuItemSolveConflict); componentContextMenu.Opened += ComponentContextMenu_Opened; // Context menu for the channels channelContextMenu = new ContextMenu(); MenuItem channelContextMenuItemDelete = new MenuItem(); channelContextMenuItemDelete.Header = Properties.Resources.ChannelContextMenuDeleteChannel; channelContextMenuItemDelete.Click += ChannelContextItemDelete_Click; channelContextMenu.Items.Add(channelContextMenuItemDelete); channelContextMenu.Opened += ChannelContextMenu_Opened; // Context menu for the event channels eventChannelContextMenu = new ContextMenu(); MenuItem eventChannelContextMenuItemDelete = new MenuItem(); eventChannelContextMenuItemDelete.Header = Properties.Resources.EventChannelContextMenuDeleteChannel; eventChannelContextMenuItemDelete.Click += EventChannelContextItemDelete_Click; eventChannelContextMenu.Items.Add(eventChannelContextMenuItemDelete); MenuItem eventChannelContextMenuItemEvents = new MenuItem(); eventChannelContextMenuItemEvents.Header = Properties.Resources.EventChannelContextMenuSetEvents; eventChannelContextMenuItemEvents.Click += EventChannelContextItemSetEvents_Click; eventChannelContextMenu.Items.Add(eventChannelContextMenuItemEvents); eventChannelContextMenu.Opened += EventChannelContextMenu_Opened; // load all components to the ribbon menu LoadBundle(null); // initialize the model for drawing a new schema deploymentModel = new ACS.model(); deploymentModel.channels = new channel[1]; deploymentModel.eventChannels = new eventChannel[0]; deploymentModel.components = new componentType[1]; eventChannelLinesList = new ArrayList(); eventChannelList = new ArrayList(); NewAREGUIWindow(); DateTime dt = DateTime.UtcNow; deploymentModel.modelName = dt.ToShortDateString() + "_" + dt.Hour + dt.Minute; // Set the keyboard navigation KeyboardNavigation.SetTabIndex(canvas, 1); KeyboardNavigation.SetTabNavigation(canvas, KeyboardNavigationMode.Cycle); asapiNet = new AsapiNetMain(); redoStack = new AstericsStack<CommandObject>(); undoStack = new AstericsStack<CommandObject>(); undoStack.PropertyChanged += undoStack_PropertyChanged; redoStack.PropertyChanged += redoStack_PropertyChanged; // Creating the AvalonDock (split window and properties on the right hand side) BuildDockingLayout(); // init dummy element pasteDummyName += (char) 86; pasteDummyName += (char)101; pasteDummyName += (char)105; pasteDummyName += (char)103; pasteDummyName += (char)108; pasteDummyName += (char)49; pasteDummyName += (char)50; pasteDummyName += (char)51; pasteDummyName += (char)53; pasteDummyName += (char)56; // read options from ini-file String tmp = ini.IniReadValue("Options", "showNamingDialogOnComponentInsert"); if (tmp.Equals("true")) { showNamingDialogOnComponentInsert = true; } else { showNamingDialogOnComponentInsert = false; } tmp = ini.IniReadValue("Options", "showHostPortDialogOnConnect"); if (tmp.Equals("true")) { showHostPortDialogOnConnect = true; } else { showHostPortDialogOnConnect = false; } tmp = ini.IniReadValue("Options", "showEventChannelConnectMessage"); if (tmp.Equals("true")) { showEventChannelConnectMessage = true; } else { showEventChannelConnectMessage = false; } tmp = ini.IniReadValue("Options", "showAREConnectedMessage"); if (tmp.Equals("true")) { showAREConnectedMessage = true; } else { showAREConnectedMessage = false; } tmp = ini.IniReadValue("Options", "showOverrideModelQuestion"); if (tmp.Equals("true")) { showOverrideModelQuestion = true; } else { showOverrideModelQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideLocalModelQuestion"); if (tmp.Equals("true")) { showOverrideLocalModelQuestion = true; } else { showOverrideLocalModelQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideLocalWhenConnected"); if (tmp.Equals("true")) { showOverrideAtConnectionQuestion = true; } else { showOverrideAtConnectionQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideAndRunLocalWhenConnected"); if (tmp.Equals("true")) { showOverrideAndRunAtConnectionQuestion = true; } else { showOverrideAndRunAtConnectionQuestion = false; } tmp = ini.IniReadValue("Options", "showOverrideComponentCollectionQuestion"); if (tmp.Equals("true")) { showOverrideComponentCollectionQuestion = true; } else { showOverrideComponentCollectionQuestion = false; } // Eventhandler needed to read start parameter (start file after double-click) this.Loaded += new RoutedEventHandler(MainWindow_Loaded); areStatus = new AREStatus(); //AREStatus.Disconnected; areStatus.PropertyChanged += AreStatusChanged; statusBar.Text = Properties.Resources.AREStatusDisconnected; statusList = new List<StatusObject>(); //showPortsRibbonButton.IsChecked = true; //showEventsRibbonButton.IsChecked = true; this.KeyDown += Global_KeyDown; canvas.MouseWheel += Zoom_MouseWheele; canvas.Focusable = true; canvas.Focus(); //Adding event handlers to the selected Elemts lists. selectedComponentList.PropertyChanged += LinkedList_SizeChanged; selectedChannelList.PropertyChanged += LinkedList_SizeChanged; selectedEventChannelList.PropertyChanged += LinkedList_SizeChanged; // make sure a file for recently opened documents exists if (ini.IniReadValue("Options", "useAppDataFolder").Equals("true")) { if (!File.Exists(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\recent.txt")) { File.Create(Environment.GetFolderPath(System.Environment.SpecialFolder.ApplicationData) + "\\AsTeRICS\\ACS\\recent.txt"); } } else { if (!File.Exists(AppDomain.CurrentDomain.BaseDirectory + "recent.txt")) { File.Create(AppDomain.CurrentDomain.BaseDirectory + "recent.txt"); } } }
public void WriteTest() { using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\t\r\n", data, "#01"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "data"); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\tdata\r\n", data, "#02"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "data", "data2"); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\tdata\tdata2\r\n", data, "#03"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceEvent (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "msg"); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\tmsg\r\n", data, "#04"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceEvent (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "msg:{0}", "arg1"); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\tmsg:arg1\r\n", data, "#05"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceOutputOptions = System.Diagnostics.TraceOptions.DateTime | System.Diagnostics.TraceOptions.LogicalOperationStack | System.Diagnostics.TraceOptions.ProcessId | System.Diagnostics.TraceOptions.ThreadId | System.Diagnostics.TraceOptions.Timestamp; log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\t\t\"\"\t" + cache.DateTime.ToString ("u", CultureInfo.InvariantCulture) + "\t" + cache.ProcessId + "\t" + cache.ThreadId + "\t" + cache.Timestamp + System.Environment.NewLine, data, "#06"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Filter = new System.Diagnostics.EventTypeFilter (System.Diagnostics.SourceLevels.All); log.IncludeHostName = true; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache (); log.TraceOutputOptions = System.Diagnostics.TraceOptions.DateTime | System.Diagnostics.TraceOptions.LogicalOperationStack | System.Diagnostics.TraceOptions.ProcessId | System.Diagnostics.TraceOptions.ThreadId | System.Diagnostics.TraceOptions.Timestamp; log.TraceData (cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close (); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText (filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile (filename); Assert.AreEqual ("nunit\tCritical\t0\t\t\"\"\t" + cache.DateTime.ToString ("u", CultureInfo.InvariantCulture) + "\t" + cache.ProcessId + "\t" + cache.ThreadId + "\t" + cache.Timestamp + "\t" + Environment.MachineName + System.Environment.NewLine, data, "#07"); } }
public void FilenameTest() { using (FileLogTraceListener log = new FileLogTraceListener ()) { log.LogFileCreationSchedule = LogFileCreationScheduleOption.None; log.Location = LogFileLocation.CommonApplicationDirectory; Assert.AreEqual (System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "#A1"); log.Location = LogFileLocation.ExecutableDirectory; Assert.AreEqual (System.IO.Path.Combine (System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + ".log", log.FullLogFileName, "#A2"); log.Location = LogFileLocation.LocalUserApplicationDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "#A3"); log.Location = LogFileLocation.TempDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + ".log", log.FullLogFileName, "#A4"); log.Location = LogFileLocation.Custom; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "#A5"); log.CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) + ".log", log.FullLogFileName, "#A6"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { log.LogFileCreationSchedule = LogFileCreationScheduleOption.Daily; log.Location = LogFileLocation.CommonApplicationDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B1"); log.Location = LogFileLocation.ExecutableDirectory; Assert.AreEqual (System.IO.Path.Combine (System.IO.Path.GetDirectoryName (System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B2"); log.Location = LogFileLocation.LocalUserApplicationDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B3"); log.Location = LogFileLocation.TempDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B4"); log.Location = LogFileLocation.Custom; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B5"); log.CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) + DateTime.Now.ToString ("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B6"); } using (FileLogTraceListener log = new FileLogTraceListener ()) { DateTime dt = DateTime.Today.AddDays (-(int)DateTime.Today.DayOfWeek); string format = dt.ToString ("-yyyy-MM-dd"); log.LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly; log.Location = LogFileLocation.CommonApplicationDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C1"); log.Location = LogFileLocation.ExecutableDirectory; Assert.AreEqual (System.IO.Path.Combine (System.IO.Path.GetDirectoryName (System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + format + ".log", log.FullLogFileName, "#C2"); log.Location = LogFileLocation.LocalUserApplicationDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C3"); log.Location = LogFileLocation.TempDirectory; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C4"); log.Location = LogFileLocation.Custom; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C5"); log.CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments; Assert.AreEqual (System.IO.Path.Combine (Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C6"); } }
public void DiskSpaceTest3() { using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Location = LogFileLocation.TempDirectory; log.MaxFileSize = 1000; log.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.ThrowException; log.Write (new string('z', 1001)); } }
public void DiskSpaceTest2() { using (FileLogTraceListener log = new FileLogTraceListener ()) { log.MaxFileSize = 0; } }
public void DiskSpaceTest1() { using (FileLogTraceListener log = new FileLogTraceListener ()) { log.Location = LogFileLocation.TempDirectory; log.ReserveDiskSpace = new System.IO.DriveInfo (log.FullLogFileName [0].ToString ()).TotalFreeSpace; log.DiskSpaceExhaustedBehavior = DiskSpaceExhaustedOption.ThrowException; log.WriteLine ("TestLine"); } }
public void DiskSpaceTest2() { using (FileLogTraceListener log = new FileLogTraceListener()) { log.MaxFileSize = 0; } }
public void WriteTest() { using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\t\r\n", data, "#01"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "data"); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\tdata\r\n", data, "#02"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "data", "data2"); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\tdata\tdata2\r\n", data, "#03"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceEvent(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "msg"); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\tmsg\r\n", data, "#04"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceEvent(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, "msg:{0}", "arg1"); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\tmsg:arg1\r\n", data, "#05"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceOutputOptions = System.Diagnostics.TraceOptions.DateTime | System.Diagnostics.TraceOptions.LogicalOperationStack | System.Diagnostics.TraceOptions.ProcessId | System.Diagnostics.TraceOptions.ThreadId | System.Diagnostics.TraceOptions.Timestamp; log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\t\t\"\"\t" + cache.DateTime.ToString("u", CultureInfo.InvariantCulture) + "\t" + cache.ProcessId + "\t" + cache.ThreadId + "\t" + cache.Timestamp + System.Environment.NewLine, data, "#06"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.Filter = new System.Diagnostics.EventTypeFilter(System.Diagnostics.SourceLevels.All); log.IncludeHostName = true; string filename = log.FullLogFileName; string data; System.Diagnostics.TraceEventCache cache = new System.Diagnostics.TraceEventCache(); log.TraceOutputOptions = System.Diagnostics.TraceOptions.DateTime | System.Diagnostics.TraceOptions.LogicalOperationStack | System.Diagnostics.TraceOptions.ProcessId | System.Diagnostics.TraceOptions.ThreadId | System.Diagnostics.TraceOptions.Timestamp; log.TraceData(cache, "nunit", System.Diagnostics.TraceEventType.Critical, 0, null); log.Close(); data = Microsoft.VisualBasic.FileIO.FileSystem.ReadAllText(filename); Microsoft.VisualBasic.FileIO.FileSystem.DeleteFile(filename); Assert.AreEqual("nunit\tCritical\t0\t\t\"\"\t" + cache.DateTime.ToString("u", CultureInfo.InvariantCulture) + "\t" + cache.ProcessId + "\t" + cache.ThreadId + "\t" + cache.Timestamp + "\t" + Environment.MachineName + System.Environment.NewLine, data, "#07"); } }
public void FilenameTest() { using (FileLogTraceListener log = new FileLogTraceListener()) { log.LogFileCreationSchedule = LogFileCreationScheduleOption.None; log.Location = LogFileLocation.CommonApplicationDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "#A1"); log.Location = LogFileLocation.ExecutableDirectory; Assert.AreEqual(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + ".log", log.FullLogFileName, "#A2"); log.Location = LogFileLocation.LocalUserApplicationDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "#A3"); log.Location = LogFileLocation.TempDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + ".log", log.FullLogFileName, "#A4"); log.Location = LogFileLocation.Custom; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + ".log", log.FullLogFileName, "#A5"); log.CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) + ".log", log.FullLogFileName, "#A6"); } using (FileLogTraceListener log = new FileLogTraceListener()) { log.LogFileCreationSchedule = LogFileCreationScheduleOption.Daily; log.Location = LogFileLocation.CommonApplicationDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B1"); log.Location = LogFileLocation.ExecutableDirectory; Assert.AreEqual(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B2"); log.Location = LogFileLocation.LocalUserApplicationDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B3"); log.Location = LogFileLocation.TempDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B4"); log.Location = LogFileLocation.Custom; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B5"); log.CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) + DateTime.Now.ToString("-yyyy-MM-dd") + ".log", log.FullLogFileName, "#B6"); } using (FileLogTraceListener log = new FileLogTraceListener()) { DateTime dt = DateTime.Today.AddDays(-(int)DateTime.Today.DayOfWeek); string format = dt.ToString("-yyyy-MM-dd"); log.LogFileCreationSchedule = LogFileCreationScheduleOption.Weekly; log.Location = LogFileLocation.CommonApplicationDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.AllUsersApplicationData, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C1"); log.Location = LogFileLocation.ExecutableDirectory; Assert.AreEqual(System.IO.Path.Combine(System.IO.Path.GetDirectoryName(System.Windows.Forms.Application.ExecutablePath), log.BaseFileName) + format + ".log", log.FullLogFileName, "#C2"); log.Location = LogFileLocation.LocalUserApplicationDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C3"); log.Location = LogFileLocation.TempDirectory; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.Temp, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C4"); log.Location = LogFileLocation.Custom; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.CurrentUserApplicationData, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C5"); log.CustomLocation = Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments; Assert.AreEqual(System.IO.Path.Combine(Microsoft.VisualBasic.FileIO.SpecialDirectories.MyDocuments, log.BaseFileName) + format + ".log", log.FullLogFileName, "#C6"); } }