Exemplo n.º 1
0
 // Write text to the StrandedFound-YYYY-MM-DD.log daily log file located in the same folder where Stranded.exe resides.
 private static void log(string text)
 {
     if (_tl != null)
     {
         _tl.WriteLine(text);
     }
 }
 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");
     }
 }
Exemplo n.º 3
0
 /// <summary>
 /// Write the \e message text to STDOUT, to [weekly log files](@ref AcUtils#AcDebug#initAcLogging) located
 /// in <tt>\%LOCALAPPDATA\%\\AcTools\\Logs</tt>, and to \c trigger.log in the AccuRev server's
 /// <tt>..storage\\site_slice\\logs</tt> folder in the case of triggers.
 /// </summary>
 /// <param name="message">The text to be logged.</param>
 /// <param name="formatting">\e true to include the date, time and newline formatting in the log file.
 /// \e false for no formatting.</param>
 /*! \sa Log(string, string, bool) */
 public static void Log(string message, bool formatting = true)
 {
     lock (_locker)
     {
         Console.WriteLine(message); // to STDOUT and trigger.log
         if (_log != null)
         {
             if (formatting)
             {
                 // include date/time in our log file and separate each log entry with an empty line
                 _log.WriteLine($"{DateTime.Now.ToString()}{Environment.NewLine}{message}{Environment.NewLine}");
             }
             else
             {
                 _log.WriteLine(message);
             }
         }
     }
 }
Exemplo n.º 4
0
        /// <summary>
        /// 写入一行日志
        /// </summary>
        /// <param name="LogMessage">日志消息</param>
        /// <param name="LogType">日志类型</param>
        public static void WriteLog(string LogMessage, LogTypes LogType = LogTypes.INFO)
        {
            string Message = string.Format(
                @"\{0}/   <{1}>   {2}",
                DateTime.Now.ToString("yyyy/MM/dd-hh:mm:ss.fff"),
                LogType.ToString().PadRight(5),
                LogMessage
                );

            LogListener?.WriteLine(Message);
            System.Diagnostics.Debug.Print(Message);
        }
Exemplo n.º 5
0
        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();
        }
Exemplo n.º 6
0
        /// <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 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");
     }
 }