solarApp 加入log part1

This commit is contained in:
Kai 2021-11-03 18:26:53 +08:00
parent a3f69e0d4d
commit 4222995724
4 changed files with 38 additions and 7 deletions

View File

@ -44,7 +44,7 @@ namespace SolarPower.Quartz.Jobs
if (this.environment.IsDevelopment())
{
dateTime = "2021-08-16 09";
dateTime = "2021-11-02 10";
}
logger.LogInformation("【CalcPowerStationJob】【任務開始】");
@ -107,12 +107,18 @@ namespace SolarPower.Quartz.Jobs
{
logger.LogInformation("【CalcPowerStationJob】【開始取得電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
var history = await powerStationRepository.GetPowerStationHistoryPerHour(dateTime, full_table_name);
// 當前用不到
// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
if (history == null)
{
logger.LogWarning("【CalcPowerStationJob】【查無電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
}
else
{
logger.LogInformation("【CalcPowerStationJob】【取得成功電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
logger.LogInformation("【CalcPowerStationJob】【電站[{0}]在{1}的每小時歷史資料】 - {2}", powerStation.Code, dateTime, System.Text.Json.JsonSerializer.Serialize(history));
var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
if (history != null)
{
logger.LogInformation("【CalcPowerStationJob】【開始計算電站[{0}]在{1}的每小時歷史資料】", powerStation.Code, dateTime);
history.PowerStationId = powerStation.Id;
history.Timestamp = Convert.ToDateTime(history.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
@ -303,9 +309,13 @@ namespace SolarPower.Quartz.Jobs
//pyrheliometerHistory.Timestamp = Convert.ToDateTime(pyrheliometerHistory.Timestamp + ":00:00").ToString("yyyy-MM-dd HH:mm:ss");
//pyrheliometerHistory.PowerStationId = powerStation.Id;
//pyrheliometerHistoriesHour.Add(pyrheliometerHistory);
}
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime);
}
else
{
logger.LogWarning("【CalcPowerStationJob】【查無結果電站[{0}]在{1}的日照計的平均值】", powerStation.Code, dateTime);
}
}
}
catch (Exception ex)
{
@ -334,6 +344,10 @@ namespace SolarPower.Quartz.Jobs
logger.LogInformation("【CalcPowerStationJob】【計算完成電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime);
}
else
{
logger.LogWarning("【CalcPowerStationJob】【查無結果電站[{0}]在{1}的模組溫度計的平均值】", powerStation.Code, dateTime);
}
}
}
catch (Exception ex)

View File

@ -1,3 +1,4 @@
using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
@ -14,12 +15,22 @@ namespace solarApp
[STAThread]
static void Main()
{
Log.Logger = new LoggerConfiguration()
.MinimumLevel.Verbose() // 設定最低顯示層級 預設: Information
.WriteTo.File("Logs/solarApp/log-.log",
rollingInterval: RollingInterval.Day, // 每天一個檔案
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u5}] {Message:lj}{NewLine}{Exception}"
) // 輸出到檔案 檔名範例: log-20211005.log
.CreateLogger();
Application.SetHighDpiMode(HighDpiMode.SystemAware);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
//Application.Run(new fmExcel());
Application.Run(new fmArchive());
//Application.Run(new fmMain());
Log.CloseAndFlush();
}
}
}

View File

@ -6,6 +6,7 @@ using Dapper;
using solarApp.Model;
using System.Configuration;
using System.Threading.Tasks;
using Serilog;
namespace solarApp.Service
{
@ -116,6 +117,7 @@ namespace solarApp.Service
string ss = @"SET SESSION sql_mode=(SELECT REPLACE(@@sql_mode,'ONLY_FULL_GROUP_BY,',''));";
conn.Execute(ss);
Log.Information("開始執行[{0}]在{1}逆變器15min補償", _siteID, _date1);
#region 15 min
string sql = @"
INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP)
@ -146,6 +148,8 @@ namespace solarApp.Service
group by FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d %H') , inverterid
) a join " + _siteDB + @".inverter b on a.inverterid = b.inverterid";
var ds = conn.Execute(sql, new { date1 = _date1, PowerStationID = _powerStationID });
Log.Information("執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1);
#endregion
#region hour

View File

@ -21,6 +21,8 @@
<ItemGroup>
<PackageReference Include="Dapper" Version="2.0.90" />
<PackageReference Include="MySql.Data" Version="8.0.26" />
<PackageReference Include="Serilog.Extensions.Logging.File" Version="2.0.0" />
<PackageReference Include="Serilog.Sinks.File" Version="5.0.0" />
</ItemGroup>
</Project>