diff --git a/TomatoLog.Server/Plugins/TomatoLog.ToFile/TomatoLog.ToFile.dll b/TomatoLog.Server/Plugins/TomatoLog.ToFile/TomatoLog.ToFile.dll index f1c5974..132662d 100644 Binary files a/TomatoLog.Server/Plugins/TomatoLog.ToFile/TomatoLog.ToFile.dll and b/TomatoLog.Server/Plugins/TomatoLog.ToFile/TomatoLog.ToFile.dll differ diff --git a/TomatoLog.Server/Plugins/TomatoLog.ToMongoDB/TomatoLog.ToMongoDB.deps.json b/TomatoLog.Server/Plugins/TomatoLog.ToMongoDB/TomatoLog.ToMongoDB.deps.json index 03fec2c..649ad31 100644 --- a/TomatoLog.Server/Plugins/TomatoLog.ToMongoDB/TomatoLog.ToMongoDB.deps.json +++ b/TomatoLog.Server/Plugins/TomatoLog.ToMongoDB/TomatoLog.ToMongoDB.deps.json @@ -1735,7 +1735,7 @@ "System.Linq.Expressions/4.1.0": { "type": "package", "serviceable": true, - "sha512": "sha512-I+y02iqkgmCAyfbqOmSDOgqdZQ5tTj80Akm5BPSS8EeB0VGWdy6X1KCoYe8Pk6pwDoAKZUOdLVxnTJcExiv5zw==", + "sha512": "sha512-u2hTii1wBVnvBT4tMNCDGTEKHN47Q02gyYjl6CNNM7nrLJImWNVsWL6uAzLE8IGop7SDpHfiHs+5mO0hYOXc7w==", "path": "system.linq.expressions/4.1.0", "hashPath": "system.linq.expressions.4.1.0.nupkg.sha512" }, diff --git a/TomatoLog.sln b/TomatoLog.sln index 0202219..95016ea 100644 --- a/TomatoLog.sln +++ b/TomatoLog.sln @@ -1,7 +1,7 @@  Microsoft Visual Studio Solution File, Format Version 12.00 -# Visual Studio 15 -VisualStudioVersion = 15.0.28307.329 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 MinimumVisualStudioVersion = 10.0.40219.1 Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{299FA2FB-6403-4AF5-ABC8-04E7F9EBA4DB}" EndProject diff --git a/src/TomatoLog.Server/Properties/launchSettings.json b/src/TomatoLog.Server/Properties/launchSettings.json index 9eca747..1c36ff1 100644 --- a/src/TomatoLog.Server/Properties/launchSettings.json +++ b/src/TomatoLog.Server/Properties/launchSettings.json @@ -1,27 +1,12 @@ { - "iisSettings": { - "windowsAuthentication": false, - "anonymousAuthentication": true, - "iisExpress": { - "applicationUrl": "http://localhost:53180/", - "sslPort": 0 - } - }, "profiles": { - "IIS Express": { - "commandName": "IISExpress", - "launchBrowser": true, - "environmentVariables": { - "ASPNETCORE_ENVIRONMENT": "Development" - } - }, "TomatoLog.Server": { "commandName": "Project", "launchBrowser": true, "environmentVariables": { "ASPNETCORE_ENVIRONMENT": "Development" }, - "applicationUrl": "http://localhost:53182/" + "applicationUrl": "http://localhost:20272/" } } } \ No newline at end of file diff --git a/src/TomatoLog.Server/Views/Config/Index.cshtml b/src/TomatoLog.Server/Views/Config/Index.cshtml index 3f1f8c4..c4e4734 100644 --- a/src/TomatoLog.Server/Views/Config/Index.cshtml +++ b/src/TomatoLog.Server/Views/Config/Index.cshtml @@ -13,14 +13,14 @@ var email = Model.Email; } -
+
-

Global Config

-
+

Global Configuration

+
-
+
-
+
Enable Report stage(Seconds) Trigger threshold @@ -37,17 +37,17 @@
-
+
-
+
-
+
Enable Url HttpMethoed @@ -57,17 +57,17 @@
-
+
-
+
-
+
Enable Mailbox Password diff --git a/src/TomatoLog.Server/Views/Home/Index.cshtml b/src/TomatoLog.Server/Views/Home/Index.cshtml index d8d0289..9945127 100644 --- a/src/TomatoLog.Server/Views/Home/Index.cshtml +++ b/src/TomatoLog.Server/Views/Home/Index.cshtml @@ -3,7 +3,7 @@ List projs = ViewBag.Projects; }
-

Project List

+

Project List

@foreach (var p in projs) { @@ -22,4 +22,5 @@
}
+
\ No newline at end of file diff --git a/src/TomatoLog.Server/Views/ProConfig/Detail.cshtml b/src/TomatoLog.Server/Views/ProConfig/Detail.cshtml index 07db244..a8f758e 100644 --- a/src/TomatoLog.Server/Views/ProConfig/Detail.cshtml +++ b/src/TomatoLog.Server/Views/ProConfig/Detail.cshtml @@ -9,7 +9,7 @@ } } -
+
@@ -22,13 +22,20 @@
} -

Report Config

+ - - Back to list -
-
-
+
+
+

Report Config

+
+
+ + Back to list +
+
+
+
Root Configuration
+
ProjectName Enable Report stage(Seconds) @@ -37,9 +44,9 @@
-
-
-
+
+
Sms Configuration
+
Enable Url HttpMethoed @@ -48,9 +55,9 @@
-
-
-
+
+
Email Configuration
+
Enable Mailbox Password @@ -81,4 +88,4 @@ } } -
\ No newline at end of file +
diff --git a/src/TomatoLog.Server/Views/ProConfig/Index.cshtml b/src/TomatoLog.Server/Views/ProConfig/Index.cshtml index 4d66bf4..876ef8d 100644 --- a/src/TomatoLog.Server/Views/ProConfig/Index.cshtml +++ b/src/TomatoLog.Server/Views/ProConfig/Index.cshtml @@ -3,36 +3,40 @@ -

Project Config

- - - - - - - - - - - - - @foreach (var c in Model) - { - var sett = c.Setting; - - - - - - - +
+
+

Project Config

+
+
ProjectNameOnTimeCountLevelsOptions+New
@sett.ProjectName@sett.On@sett.Time@sett.Count@sett.Levels - Detail - Delete -
+ + + + + + + + - } - -
ProjectNameOnTimeCountLevelsOptions+New
+ + + @foreach (var c in Model) + { + var sett = c.Setting; + + @sett.ProjectName + @sett.On + @sett.Time + @sett.Count + @sett.Levels + + Detail + Delete + + + } + + +
@section Scripts{ diff --git a/src/TomatoLog.Server/Views/Shared/SySVariables.cshtml b/src/TomatoLog.Server/Views/Shared/SySVariables.cshtml index 31ad189..b1e6c5b 100644 --- a/src/TomatoLog.Server/Views/Shared/SySVariables.cshtml +++ b/src/TomatoLog.Server/Views/Shared/SySVariables.cshtml @@ -1,9 +1,9 @@ -
+
-
+
-
+
  • Events Timestamp:{Timestamp}
  • Source IP:{IP}
  • diff --git a/src/TomatoLog.Server/appsettings.Development.json b/src/TomatoLog.Server/appsettings.Development.json index 6c55a00..3d32a08 100644 --- a/src/TomatoLog.Server/appsettings.Development.json +++ b/src/TomatoLog.Server/appsettings.Development.json @@ -21,7 +21,7 @@ "Others": null }, "Flow": { - "Type": "Kafka", // Redis/RabbitMQ/Kafka + "Type": "RabbitMQ", // Redis/RabbitMQ/Kafka "Redis": { "Connection": "127.0.0.1:6379,defaultDatabase=10,password=123456,prefix=TomatoLog,abortConnect=false", "Channel": "TomatoLogChannel" diff --git a/src/TomatoLog.Server/wwwroot/css/site.css b/src/TomatoLog.Server/wwwroot/css/site.css index 0c9ad86..210494d 100644 --- a/src/TomatoLog.Server/wwwroot/css/site.css +++ b/src/TomatoLog.Server/wwwroot/css/site.css @@ -49,3 +49,6 @@ } .log-list .col-sm-2{padding-left:0px;padding-right:5px;margin-bottom:5px;max-width:200px;text-align:center;} .hidden {display: none;} +.warning-config .card { + margin-bottom: 20px; +} \ No newline at end of file diff --git a/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQChannel.cs b/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQChannel.cs index 5394380..6051548 100644 --- a/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQChannel.cs +++ b/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQChannel.cs @@ -22,10 +22,8 @@ public class MQChannel public void Publish(string content) { byte[] body = MQConnection.UTF8.GetBytes(content); - IBasicProperties prop = new BasicProperties - { - DeliveryMode = 1 - }; + IBasicProperties prop = Consumer.Model.CreateBasicProperties(); + prop.DeliveryMode = 1; Consumer.Model.BasicPublish(this.ExchangeName, this.RoutekeyName, false, prop, body); } @@ -34,7 +32,7 @@ internal void Receive(object sender, BasicDeliverEventArgs e) MessageBody msgBody = new MessageBody(); try { - string content = MQConnection.UTF8.GetString(e.Body); + string content = MQConnection.UTF8.GetString(e.Body.ToArray()); msgBody.Content = content; msgBody.Consumer = (EventingBasicConsumer)sender; msgBody.BasicDeliver = e; diff --git a/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQConnection.cs b/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQConnection.cs index 4f5e08d..f5b1999 100644 --- a/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQConnection.cs +++ b/src/clients/TomatoLog.Client.RabbitMQ/MQHelper/MQConnection.cs @@ -69,9 +69,9 @@ public MQChannel CreateReceiveChannel(string exchangeType, string exchange, stri IModel model = this.CreateModel(exchangeType, exchange, queue, routekey); model.BasicQos(0, 1, false); EventingBasicConsumer consumer = this.Receive(model, queue); - consumer.Registered += (object sender, ConsumerEventArgs e) => { _logger?.LogDebug($"已注册消费队列,{e.ConsumerTag}"); }; + consumer.Registered += (object sender, ConsumerEventArgs e) => { _logger?.LogDebug($"已注册消费队列,{string.Join(",", e.ConsumerTags)}"); }; consumer.Shutdown += (object sender, ShutdownEventArgs e) => { _logger?.LogDebug($"已关闭消费队列,{e.ReplyCode},{e.ReplyText}"); }; - consumer.ConsumerCancelled += (object sender, ConsumerEventArgs e) => { _logger?.LogDebug($"已退出消费队列,{e.ConsumerTag}"); }; + consumer.ConsumerCancelled += (object sender, ConsumerEventArgs e) => { _logger?.LogDebug($"已退出消费队列,{string.Join(",", e.ConsumerTags)}"); }; MQChannel channel = new MQChannel() { diff --git a/src/clients/TomatoLog.Client.RabbitMQ/TomatoLog.Client.RabbitMQ.csproj b/src/clients/TomatoLog.Client.RabbitMQ/TomatoLog.Client.RabbitMQ.csproj index cbdb047..236b5c4 100644 --- a/src/clients/TomatoLog.Client.RabbitMQ/TomatoLog.Client.RabbitMQ.csproj +++ b/src/clients/TomatoLog.Client.RabbitMQ/TomatoLog.Client.RabbitMQ.csproj @@ -5,7 +5,7 @@ true true https://github.com/lianggx/TomatoLog/blob/master/LICENSE - 1.2.0 + 1.2.1 lianggx TomatoLog https://github.com/lianggx/TomatoLog @@ -14,7 +14,7 @@ - + diff --git a/src/plugins/TomatoLog.ToFile/FileLogWriterImpl.cs b/src/plugins/TomatoLog.ToFile/FileLogWriterImpl.cs index 16ab312..4709460 100644 --- a/src/plugins/TomatoLog.ToFile/FileLogWriterImpl.cs +++ b/src/plugins/TomatoLog.ToFile/FileLogWriterImpl.cs @@ -11,13 +11,62 @@ using System.Text; using System.Threading.Tasks; using System.Linq; +using System.Threading; +using System.Collections.Concurrent; namespace TomatoLog.ToFile { public class FileLogWriterImpl : LogWriter { + private const int period = 3000; + private const int dueTime = 5000; + private Timer timer = null; + private ConcurrentQueue queue = null; + private bool runing = false; public FileLogWriterImpl(StorageOptions options, ILogger log) : base(options, log) { + timer = new Timer(new TimerCallback(TimerCallbackFlush)); + timer.Change(dueTime, period); + queue = new ConcurrentQueue(); + } + + private void TimerCallbackFlush(object sender) + { + if (runing) + return; + else + runing = true; + + try + { + int count = queue.Count; + if (count == 0) + { + runing = false; + return; + } + for (int i = 0; i < count; i++) + { + LogMessage message = null; + queue.TryDequeue(out message); + if (message == null) + continue; + + var fileName = CreateFile(message); + using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) + { + var log = JsonConvert.SerializeObject(message, Formatting.None); + StreamWriter sw = new StreamWriter(fs); + sw.WriteLine(log); + sw.Flush(); + } + } + } + catch (Exception e) + { + logger.LogError(e.Message, e); + } + runing = false; } private string CreateFile(LogMessage message) @@ -27,7 +76,7 @@ private string CreateFile(LogMessage message) if (!Directory.Exists(path)) Directory.CreateDirectory(path); - var fileName = string.Format("{1}-{2}.log", path, message.LogLevel, DateTime.Now.ToString("yyyy-MM-dd")); + var fileName = string.Format("{0}-{1}.log", message.LogLevel, DateTime.Now.ToString("yyyy-MM-dd")); var fullFileName = Path.Combine(path, fileName); return fullFileName; } @@ -45,23 +94,16 @@ private List GetDir(string path) public override async Task Write(LogMessage message) { - int affrows = 0; try { - var fileName = CreateFile(message); - var log = JsonConvert.SerializeObject(message, Formatting.None); - using (FileStream fs = new FileStream(fileName, FileMode.Append, FileAccess.Write, FileShare.ReadWrite)) - { - StreamWriter sw = new StreamWriter(fs); - await sw.WriteLineAsync(log); - await sw.FlushAsync(); - } + queue.Enqueue(message); + return queue.Count; } catch (Exception e) { logger.LogError(e.Message, e); } - return affrows; + return 0; } public override async Task> GetProjects()