solarApp 加入log part1
This commit is contained in:
parent
a3f69e0d4d
commit
4222995724
@ -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);
|
||||
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);
|
||||
// 當前用不到
|
||||
// var lastmoneyhistorybyhour = await powerStationRepository.GetLastMoneyAndCarbonInHour(powerStation.Id, 0, dateTime);
|
||||
|
||||
if (history != null)
|
||||
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));
|
||||
|
||||
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,8 +309,12 @@ 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);
|
||||
}
|
||||
logger.LogInformation("【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)
|
||||
|
||||
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -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,10 +148,12 @@ 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
|
||||
sql = @"
|
||||
sql = @"
|
||||
insert into solar_master.inverter_history_hour (PowerStationId, INVERTERID, TIMESTAMP, Irradiance, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH,
|
||||
AC3V, AC3A, AC3W, AC3F, AC3WH, DC1V, DC1A, DC1W, DC1WH, DC2V, DC2A, DC2W, DC2WH, DC3V, DC3A, DC3W, DC3WH, DC4V, DC4A, DC4W, DC4WH, DC5V, DC5A, DC5W, DC5WH,
|
||||
PR, RA1, RA2, RA3, RA4, RA5, DCKW, ACKW, KWH, TODAYKWH, TOTALKWH, KWHKWP)
|
||||
|
||||
@ -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>
|
||||
Loading…
Reference in New Issue
Block a user