Beispiel #1
0
        public static void Write(string Prefix, string content, DebugLevel level = DebugLevel.Info,
			WriteWay way = WriteWay.Console, bool enable = true)
        {
            if (!enable) return;

            if (way == WriteWay.Console)
            {
                ConsoleColor color = ConsoleColor.White;
                if (level == DebugLevel.Info)
                {
                    color = ConsoleColor.DarkGreen;
                }
                else if (level == DebugLevel.Warning)
                {
                    color = ConsoleColor.Yellow;
                }
                else if (level == DebugLevel.Wrang)
                {
                    color = ConsoleColor.Red;
                }
                Console.ForegroundColor = color;
                Console.WriteLine(!string.IsNullOrEmpty(Prefix) ? (Prefix + ":"+ content) : "" + content);
                Console.ForegroundColor = ConsoleColor.White;
            }
            else
            {
                System.Drawing.Color color = System.Drawing.Color.White;
                if (level == DebugLevel.Info)
                {
                    color = System.Drawing.ColorTranslator.FromHtml("#AAAAFF");
                }
                else if (level == DebugLevel.Warning)
                {
                    color = System.Drawing.Color.Orange;
                }
                else if (level == DebugLevel.Wrang)
                {
                    color = System.Drawing.Color.Red;
                }
                content = (string.IsNullOrEmpty(Prefix) ? (Prefix + ":") : "") + content;
                Game.PrintChat(content.ToHtml(color, FontStlye.Cite));
            }
        }
Beispiel #2
0
 public static void Write(string content, DebugLevel level = DebugLevel.Info,
                          WriteWay way = WriteWay.Console, bool enable = true)
 {
     Write(null, content, level, way, enable);
 }
Beispiel #3
0
        public static void Write(string content, DebugLevel level = DebugLevel.Info,
			WriteWay way = WriteWay.Console, bool enable = true)
        {
            Write(null, content, level, way, enable);
        }
Beispiel #4
0
        private void WriteLogLine(WriteWay writeWay, string writeLogLine, params string[] logFilePath)
        {
            if (logFilePath.Length < 2)
            {
                Console.WriteLine(invalidExistLogFilePath);
                return;
            }

            string connectionString            = $"DefaultEndpointsProtocol=https;AccountName={Constant.STORAGE_ACCOUNT_NAME};AccountKey={Constant.Instance.StorageAccountKey};EndpointSuffix=core.windows.net";
            CloudStorageAccount storageAccount = CloudStorageAccount.Parse(connectionString);
            CloudFileClient     fileClient     = storageAccount.CreateCloudFileClient();

            CloudFileShare share = fileClient.GetShareReference(logFilePath[0]);

            if (!share.Exists())
            {
                share.Create();
            }
            CloudFileDirectory sampleDir = share.GetRootDirectoryReference();

            for (int i = 1; i < logFilePath.Length - 1; i++)
            {
                CloudFileDirectory nextLevelDir = sampleDir.GetDirectoryReference("TestLogs");
                if (!sampleDir.Exists())
                {
                    sampleDir.Create();
                }
                sampleDir = nextLevelDir;
            }

            CloudFile file = sampleDir.GetFileReference(logFilePath[logFilePath.Length - 1]);

            lock ("")
            {
                CloudBlobClient    blobClient    = storageAccount.CreateCloudBlobClient();
                CloudBlobContainer blobContainer = blobClient.GetContainerReference("logs");
                blobContainer.CreateIfNotExistsAsync();
                CloudBlockBlob blockBlob = blobContainer.GetBlockBlobReference("testBlob");

                List <string> blockIds = new List <string>();
                DateTime      before   = DateTime.Now;

                blockIds.AddRange(blockBlob.DownloadBlockList(BlockListingFilter.Committed).Select(b => b.Name));
                DateTime after = DateTime.Now;
                TimeSpan ts    = after.Subtract(before);
                Console.WriteLine(ts.Seconds + "_" + ts.Milliseconds);

                var newId = Convert.ToBase64String(Encoding.Default.GetBytes(blockIds.Count.ToString()));
                blockBlob.PutBlock(newId, new MemoryStream(Encoding.Default.GetBytes(writeLogLine + "\n")), null);
                blockIds.Add(newId);
                blockBlob.PutBlockList(blockIds);

                string writenLineContent = "";
                if (file.Exists())
                {
                    if (writeWay == WriteWay.Cover)
                    {
                    }
                    else if (writeWay == WriteWay.Append)
                    {
                        writenLineContent = file.DownloadTextAsync().Result;
                    }
                }
                file.UploadText(writenLineContent + writeLogLine + "\n");
            }
        }