增加 log 机制
This commit is contained in:
parent
c41d079396
commit
df2654fb57
@ -486,9 +486,9 @@ namespace SolarPower.Controllers
|
||||
vForDataCount++;
|
||||
object vv = "";
|
||||
|
||||
avghour = Convert.ToString( dbody["tothour"]) ?? "NaN";
|
||||
avgKWHKWP = Convert.ToString(dbody["KWHKWP"]) ?? "NaN";
|
||||
avgdayKWH = Convert.ToString(dbody["dayKWH"]) ?? "NaN";
|
||||
avghour = (dbody["tothour"] == null) ? "NaN" : dbody["tothour"].ToString();
|
||||
avgKWHKWP = (dbody["KWHKWP"] == null) ? "NaN" : dbody["KWHKWP"].ToString();
|
||||
avgdayKWH = (dbody["dayKWH"] == null) ? "NaN" : dbody["dayKWH"].ToString();
|
||||
|
||||
//if (dbody.TryGetValue("tothour", out vv))
|
||||
// avghour = (Convert.ToDouble(dbody["tothour"].ToString()) + Convert.ToDouble(avghour)).ToString();
|
||||
|
||||
@ -64,14 +64,20 @@ namespace solarApp
|
||||
// Console.WriteLine("Error Occured");
|
||||
// }
|
||||
// }
|
||||
// ref: https://www.ruyut.com/2021/10/serilog.html
|
||||
Log.Logger = new LoggerConfiguration()
|
||||
.MinimumLevel.Verbose() // 設定最低顯示層級 預設: Information
|
||||
.WriteTo.File("Logs/solarApp/log-.log",
|
||||
.WriteTo.File("Logs/log-.log",
|
||||
rollingInterval: RollingInterval.Day, // 每天一個檔案
|
||||
outputTemplate: "{Timestamp:HH:mm:ss} [{Level:u5}] {Message:lj}{NewLine}{Exception}"
|
||||
) // 輸出到檔案 檔名範例: log-20211005.log
|
||||
.CreateLogger();
|
||||
|
||||
//Log.Information("Init log");
|
||||
|
||||
// Log.Debug("debug");
|
||||
|
||||
|
||||
Application.SetHighDpiMode(HighDpiMode.SystemAware);
|
||||
Application.EnableVisualStyles();
|
||||
Application.SetCompatibleTextRenderingDefault(false);
|
||||
|
||||
@ -5,15 +5,16 @@ using MySql.Data.MySqlClient;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using Dapper;
|
||||
using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
using System.Windows.Forms;
|
||||
using Serilog;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
class archiveLowData
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
|
||||
private ILogger logger = Log.ForContext<archiveLowData>();
|
||||
public archiveLowData(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
@ -42,8 +43,9 @@ namespace solarApp.Service
|
||||
// string yyyymm = System.DateTime.Now.AddMonths(-2).ToString("yyyy-MM");
|
||||
_siteID = siteID;
|
||||
//搬移的月份
|
||||
move_month = System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM")+ "-01";
|
||||
// move_month = System.DateTime.Now.ToString("yyyy-MM") + "--01"; //這個月
|
||||
// move_month = System.DateTime.Now.AddMonths(-1).ToString("yyyy-MM")+ "-01";
|
||||
move_month = System.DateTime.Now.ToString("yyyy-MM") + "-01"; //這個月
|
||||
|
||||
//_date1 = date1;
|
||||
get_siteInfo();
|
||||
checkTable();
|
||||
@ -51,8 +53,6 @@ namespace solarApp.Service
|
||||
moveData_station();
|
||||
moveData_inv();
|
||||
moveData_sensor();
|
||||
|
||||
|
||||
result = true;
|
||||
|
||||
return result;
|
||||
@ -301,7 +301,7 @@ namespace solarApp.Service
|
||||
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】開始執行[{_siteDB}.s{_siteID}_station]的資料表向[{_siteDB}_history.s{_siteID}_station]搬移");
|
||||
string for_insert_station = $@"INSERT {_siteDB}_history.s{_siteID01}_station(`ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime`)
|
||||
SELECT `ID`, `TIMESTAMP`, `SITEID`, `SITETYPE`, `CONTROLLERID`, `KWH`, `TODAYKWH`, `TOTALKWH`, `KWHKWP`, `PR`, `MP`, `SOLARHOUR`, `insertTime` FROM {_siteDB}.s{_siteID01}_station
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000, '%Y-%m-%d') < '{move_month}'";
|
||||
int rowCT = conn.Execute(for_insert_station, commandTimeout : 600);
|
||||
// System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_station的七月前資料寫入至{_siteDB}_history.s{_siteID}_station【寫入成功】於{dateTime}");
|
||||
|
||||
@ -315,7 +315,9 @@ namespace solarApp.Service
|
||||
//刪除原本的資料
|
||||
string for_delete_station = $@"DELETE FROM {_siteDB}.s{_siteID01}_station
|
||||
WHERE FROM_UNIXTIME(`TIMESTAMP`/1000,'%Y-%m-%d') < '{move_month}'";
|
||||
rowCT = conn.Execute(for_delete_station, commandTimeout: 600);
|
||||
//string for_delete_station = $@"DELETE FROM {_siteDB}.s{_siteID01}_station
|
||||
// WHERE date(CrdTime) < '{move_month}'";
|
||||
rowCT = conn.Execute(for_delete_station, commandTimeout: 600);
|
||||
//System.Diagnostics.Debug.WriteLine($"【ArchiveRowData】{_siteDB}.s{_siteID}_sensoravg搬移至{_siteDB}_history.s{_siteID}_sensoravg【搬移資料成功】於{dateTime} 共 {delete_station.ToString()} 筆");
|
||||
duration = DateTime.Now - dt_start1;
|
||||
|
||||
|
||||
@ -5,6 +5,7 @@ using MySql.Data.MySqlClient;
|
||||
using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using Serilog;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -14,6 +15,9 @@ namespace solarApp.Service
|
||||
public class getStationSvc
|
||||
{
|
||||
public string Connection1 { get; set; }
|
||||
|
||||
private ILogger logger = Log.ForContext<getSensorSvc>();
|
||||
|
||||
public getStationSvc(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
@ -37,7 +41,7 @@ namespace solarApp.Service
|
||||
/// <returns></returns>
|
||||
public List<raw_statino> get_station_raw(string reportDate, string siteDB, string siteID)
|
||||
{
|
||||
List<raw_statino> ds;
|
||||
List<raw_statino> ds = null;
|
||||
using (MySqlConnection conn = new MySqlConnection(Connection1))
|
||||
{
|
||||
conn.Open();
|
||||
@ -52,7 +56,7 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
logger.Error(@$"【get_station_raw】執行失敗 {siteDB}.s{siteID} _station 在{reportDate} - [Exception]:" + ex.ToString());
|
||||
}
|
||||
return ds;
|
||||
}
|
||||
@ -104,7 +108,7 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
throw ex;
|
||||
logger.Error(@$"【get_station_rawAvg】執行失敗 {siteDB}.s{siteID} _station 在{date1} - {date2} - [Exception]:" + ex.ToString());
|
||||
}
|
||||
|
||||
return ds;
|
||||
@ -209,7 +213,7 @@ namespace solarApp.Service
|
||||
conn.Open(); // 01 控制器編號
|
||||
string sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
|
||||
from power_station
|
||||
where deleted = 0 and `status`= 1 and id <> 32 ";
|
||||
where deleted = 0 and `status`= 1 and id <> 32 ";
|
||||
if (include32)
|
||||
{
|
||||
sql = @" select id, CompanyId, `code` , SerialNumber, CONCAT(`code` ,'01') SiteID, SiteDB, `name` SiteName
|
||||
|
||||
@ -6,7 +6,8 @@ using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -14,6 +15,18 @@ namespace solarApp.Service
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
ILogger _logger;
|
||||
public ILogger MyLoger
|
||||
{
|
||||
get
|
||||
{
|
||||
if (_logger == null)
|
||||
{
|
||||
//需要添加使用的当前类名空间名称,不加的话,不显示
|
||||
_logger = Log.ForContext<procArchiveHourly>();
|
||||
}
|
||||
return _logger;
|
||||
}
|
||||
}
|
||||
public string _siteID { get; set; }
|
||||
public string _siteDB { get; set; }
|
||||
public string _siteID01 { get; set; }
|
||||
@ -44,7 +57,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
}
|
||||
|
||||
#region 取得 PowerStationID
|
||||
@ -60,7 +73,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -72,8 +85,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
throw ex;
|
||||
@ -95,7 +108,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
}
|
||||
string sql = $@"
|
||||
select x.*, z.itemname, z.HourType, z.DayType, z.MonthType,z.SetWhat
|
||||
@ -161,7 +174,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
@ -172,8 +185,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備寫入資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@ -209,8 +222,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}日照計更新至資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@ -233,7 +246,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
}
|
||||
//取前累積日照
|
||||
string sql = $@" select IrrDay
|
||||
@ -281,7 +294,7 @@ namespace solarApp.Service
|
||||
conn.Execute(ss, commandTimeout: 600);
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}累積日照差更新至資料表的資料", _siteID, _date1);
|
||||
}
|
||||
conn.Close();
|
||||
}
|
||||
@ -290,8 +303,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}累積日照差更新資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
@ -309,7 +322,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】開始執行[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
string d1 = _date1 + ":00:00";
|
||||
string clearTime = Convert.ToDateTime(d1).ToString("yyyy-MM-dd");
|
||||
@ -325,7 +338,7 @@ namespace solarApp.Service
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.Information("【ProcArchiveSensorHourly】執行完成[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
|
||||
conn.Close();
|
||||
@ -336,8 +349,8 @@ namespace solarApp.Service
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料", _siteID, _date1);
|
||||
_logger.Error("【ProcArchiveSensorHourly】執行失敗[{0}]在{1}設備清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
throw ex;
|
||||
}
|
||||
|
||||
@ -6,7 +6,9 @@ using Dapper;
|
||||
using solarApp.Model;
|
||||
using System.Configuration;
|
||||
using System.Threading.Tasks;
|
||||
using Microsoft.Extensions.Logging;
|
||||
//using Microsoft.Extensions.Logging;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
//using solarApp.Service.proArchiveLog;
|
||||
|
||||
namespace solarApp.Service
|
||||
@ -14,10 +16,10 @@ namespace solarApp.Service
|
||||
public class procInvSvc
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
ILogger _logger;
|
||||
private ILogger logger = Log.ForContext<procInvSvc>();
|
||||
|
||||
|
||||
public procInvSvc(string Connection_parame = null, ILogger logger = null)
|
||||
public procInvSvc(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
{
|
||||
@ -28,10 +30,10 @@ namespace solarApp.Service
|
||||
Connection1 = ConfigurationManager.ConnectionStrings["mySql"].ConnectionString;
|
||||
}
|
||||
|
||||
if (logger != null)
|
||||
{
|
||||
_logger = logger;
|
||||
}
|
||||
//if (logger != null)
|
||||
//{
|
||||
// _logger = logger;
|
||||
//}
|
||||
}
|
||||
|
||||
public string _siteID { get; set; }
|
||||
@ -52,10 +54,10 @@ namespace solarApp.Service
|
||||
conn.Open();
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
//if (_logger != null)
|
||||
//{
|
||||
// logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
//}
|
||||
|
||||
//string sql = @"
|
||||
// delete from inverter_history_15min where powerstationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1;
|
||||
@ -77,19 +79,14 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
}
|
||||
logger.Information(@$"【ProcInvSvc】執行完成[{_siteID}]在 {_date1} 逆變器清除資料表的資料");
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器清除資料表的資料 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
//throw ex;
|
||||
arclog.insert_log(_powerStationID, "step0 del inv ", 0, "inv", "del inv error", "0", "", "", conn, cmd);
|
||||
|
||||
@ -137,10 +134,8 @@ namespace solarApp.Service
|
||||
conn.Open();
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
}
|
||||
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
|
||||
#region 取得 PowerStationID
|
||||
string sql = @" select id , `code` siteID, siteDB, `name` siteName
|
||||
@ -153,10 +148,8 @@ namespace solarApp.Service
|
||||
_siteID01 = item.SiteID + "01";
|
||||
}
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
}
|
||||
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器取得電站編號 - {2}", _siteID, _date1, _powerStationID);
|
||||
|
||||
#endregion
|
||||
|
||||
@ -164,11 +157,10 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器取得電站編號 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
|
||||
arclog.insert_log(_powerStationID, "step0 select stationID ", 0, "stationID", "select stationID", "0", "", "", conn, null);
|
||||
}
|
||||
conn.Close();
|
||||
@ -188,29 +180,26 @@ namespace solarApp.Service
|
||||
conn.Execute(ss);
|
||||
|
||||
string sql = string.Empty;
|
||||
#region 15 min
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
}
|
||||
#region 15 min
|
||||
try
|
||||
{
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1;
|
||||
sql = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1;
|
||||
CREATE TABLE del_Inv_day_" + _powerStationID + @"_s1
|
||||
select * from " + _siteDB + ".s" + _siteID01 + @"_inv a
|
||||
WHERE left(crdTime, 10) = @date1;
|
||||
# 2. add index
|
||||
ALTER TABLE del_Inv_day_" + _powerStationID + @"_s1 ADD INDEX `temp_index` (crdTime, inverterid);";
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
//int ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 360;
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
sql = @"
|
||||
sql = @"
|
||||
INSERT INTO solar_master.inverter_history_15min( PowerStationId, TIMESTAMP, INVERTERID, KWH, TODAYKWH, KWHKWP)
|
||||
select PowerStationId, reportdate, a.inverterid, KWH, TODAYKWH, (kwh/(capacity/4)) kwpkwp from
|
||||
(
|
||||
@ -248,17 +237,13 @@ namespace solarApp.Service
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Dispose();
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器15min補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
arclog.insert_log(_powerStationID, "step1 insert inverter_15min history " + _date1, 0, "inverter_history_15min", "insert inverter_15min history", "1", "", "", conn, cmd);
|
||||
}
|
||||
#endregion
|
||||
@ -266,8 +251,7 @@ namespace solarApp.Service
|
||||
#region hour
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TEMPORARY TABLE IF EXISTS Inv_day_" + _powerStationID + @"_s2;
|
||||
CREATE TEMPORARY TABLE Inv_day_" + _powerStationID + @"_s2
|
||||
@ -323,8 +307,7 @@ namespace solarApp.Service
|
||||
//ct = conn.Execute(sql, new { date1 = _date1 });
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
|
||||
sql = @$"DROP TABLE IF EXISTS del_Inv_day_" + _powerStationID + @"_s1; ";
|
||||
//conn.Execute(ss);
|
||||
@ -333,11 +316,9 @@ namespace solarApp.Service
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器hour補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
arclog.insert_log(_powerStationID, "inverter_history_hour step1 " + _date1, 0, "inverter_history_hour", "insert inverter_history_hour error", "0", "", "", conn, cmd);
|
||||
// throw ex;
|
||||
}
|
||||
@ -347,10 +328,8 @@ namespace solarApp.Service
|
||||
#region day
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
}
|
||||
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
|
||||
sql = @"
|
||||
INSERT INTO solar_master.inverter_history_day(PowerStationId, INVERTERID, TIMESTAMP, Irradiance, IrrDay, AC1V, AC1A, AC1W, AC1F, AC1WH, AC2V, AC2A, AC2W, AC2F, AC2WH,
|
||||
@ -394,16 +373,14 @@ namespace solarApp.Service
|
||||
cmd.Parameters.Clear();
|
||||
cmd.Dispose();
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器day補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
//throw ex;
|
||||
arclog.insert_log(_powerStationID, "inverter_history_day step1 ", 0, "inverter_history_day", "insert inverter_history_day error", "0", "", ex.Message, conn, cmd);
|
||||
}
|
||||
@ -412,8 +389,8 @@ namespace solarApp.Service
|
||||
#region month
|
||||
try
|
||||
{
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【ProcInvSvc】開始執行[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
|
||||
logger.Information("【ProcInvSvc】開始執行[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
|
||||
sql = @"
|
||||
delete from inverter_history_month where powerstationID = @powerStationID and left(`TIMESTAMP`, 7) = left(@date1, 7) ;
|
||||
@ -458,18 +435,14 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【ProcInvSvc】執行完成[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
}
|
||||
|
||||
logger.Information("【ProcInvSvc】執行完成[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
_logger.LogError("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償", _siteID, _date1);
|
||||
logger.Error("【ProcInvSvc】執行失敗[{0}]在{1}逆變器month補償 - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
arclog.insert_log(_powerStationID, "inverter_history_month step1 ", 0, "inverter_history_month", "insert inverter_history_month error", "0", "", ex.Message, conn, cmd);
|
||||
// throw ex;
|
||||
}
|
||||
@ -513,10 +486,8 @@ namespace solarApp.Service
|
||||
#region get SQL
|
||||
//try
|
||||
//{
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogInformation("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
}
|
||||
|
||||
logger.Information("【Proc_inv_日報 】開始執行[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 開始建立", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "0", "", "日報 開始建立table", conn, cmd);
|
||||
#region 建立 temp table
|
||||
sql = @$"DROP TABLE IF EXISTS temp_invDay{_powerStationID}_s1;
|
||||
@ -529,7 +500,7 @@ namespace solarApp.Service
|
||||
ALTER TABLE `temp_invDay{_powerStationID}_s1` ADD INDEX `temp_indexs1` (report_date, inverterid);";
|
||||
//conn.Execute(ss);
|
||||
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 建立完成", (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", "日報 建立table完成", conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step > table 建立完成 " + _date1, (DateTime.Now - dt_start).TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", "日報 建立table完成", conn, cmd);
|
||||
|
||||
try
|
||||
{
|
||||
@ -541,7 +512,7 @@ namespace solarApp.Service
|
||||
var rowCT = cmd.ExecuteScalar();
|
||||
//select LAST_INSERT_ID()
|
||||
TimeSpan duration = DateTime.Now - dt_start;
|
||||
arclog.insert_log(_powerStationID, "report_day step1", duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", rowCT.ToString(), conn, cmd);
|
||||
arclog.insert_log(_powerStationID, "report_day step1 " + _date1, duration.TotalSeconds, "inverter_history_hour", "temp_invDay", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
}
|
||||
catch (Exception ex)
|
||||
@ -666,8 +637,7 @@ set a.inv_02 = b.inv_02 ");
|
||||
cmd.ExecuteNonQuery();
|
||||
|
||||
|
||||
if (_logger != null)
|
||||
_logger.LogInformation("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1);
|
||||
logger.Information("【Proc_inv_日報 table 】執行完成[{0}]在{1} inv_get_SQLStatement", _siteID, _date1);
|
||||
|
||||
TimeSpan duration = DateTime.Now - dt_start3;
|
||||
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "1", "", rowCT.ToString(), conn, cmd);
|
||||
@ -677,11 +647,9 @@ set a.inv_02 = b.inv_02 ");
|
||||
{
|
||||
TimeSpan duration = DateTime.Now - dt_start3 ;
|
||||
arclog.insert_log(_powerStationID, "report_day step3 update inv02", duration.TotalSeconds, "inverter_history_hour", "report_invday", "0", "", ex.Message, conn, cmd);
|
||||
if (_logger != null)
|
||||
{
|
||||
_logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
_logger.LogError("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
logger.Error("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement", _siteID, _date1);
|
||||
logger.Error("【Proc_inv_日報 table】執行失敗[{0}]在{1}inv_get_SQLStatement - [Exception]:{2}", _siteID, _date1, ex.ToString());
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
@ -9,6 +9,8 @@ using System.Threading.Tasks;
|
||||
using Google.Protobuf.WellKnownTypes;
|
||||
using MySqlX.XDevAPI.Relational;
|
||||
using static solarApp.Model.weather_model;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
@ -16,6 +18,8 @@ namespace solarApp.Service
|
||||
{
|
||||
string Connection1 = string.Empty;
|
||||
|
||||
private ILogger logger = Log.ForContext<procSensorSvc>();
|
||||
|
||||
public procSensorSvc(string Connection_parame = null)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(Connection_parame))
|
||||
@ -136,12 +140,14 @@ namespace solarApp.Service
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
conn.Close();
|
||||
logger.Information("sensor_history clearData OK");
|
||||
}
|
||||
result = true;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
//throw ex;
|
||||
logger.Error("sensor_history error: " + ex.Message);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@ -294,6 +300,7 @@ namespace solarApp.Service
|
||||
//cmd.Parameters()
|
||||
//cmd.ExecuteNonQuery();
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
|
||||
cmd.Connection = conn;
|
||||
cmd.CommandTimeout = 720;
|
||||
@ -302,9 +309,9 @@ namespace solarApp.Service
|
||||
cmd.CommandText = sql;
|
||||
int rowCT = cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
DateTime dt_start2 = DateTime.Now;
|
||||
TimeSpan duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "1", "", rowCT.ToString(), conn, cmd);
|
||||
logger.Information($@"sensor step1 insert sensor_history_hour OK duration={duration.TotalSeconds} ");
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor hour", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
// irrDayHour計算
|
||||
//sql = $@"update sensor_history_hour a join (
|
||||
@ -380,13 +387,17 @@ namespace solarApp.Service
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d')
|
||||
)b on a.reportdate = b.reportdate";
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
dt_start2 = DateTime.Now;
|
||||
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
duration = DateTime.Now - dt_start2;
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_day", "insert sensor_day", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
logger.Information($@"sensor step1 insert sensor day OK duration={duration.TotalSeconds} ");
|
||||
#endregion day
|
||||
|
||||
#region month 如果跨月 會有2筆資料
|
||||
@ -440,8 +451,12 @@ namespace solarApp.Service
|
||||
cmd.Parameters.Clear();
|
||||
arclog.insert_log(_powerStationID, "sensor step1", duration.TotalSeconds, "sensor_history_hour", "insert sensor_hour", "1", "", rowCT.ToString(), conn, cmd);
|
||||
|
||||
logger.Information($@"sensor step1 insert sensoravg_history_hour OK duration={duration.TotalSeconds} ");
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
dt_start2 = DateTime.Now;
|
||||
|
||||
foreach (var item in irrlst)
|
||||
{
|
||||
sql += @" update sensoravg_history_hour a join
|
||||
@ -460,6 +475,9 @@ namespace solarApp.Service
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
|
||||
duration = DateTime.Now - dt_start2;
|
||||
logger.Information($@"sensor step1 update sensoravg_history_hour irrAvg OK duration={duration.TotalSeconds} ");
|
||||
}
|
||||
|
||||
#endregion
|
||||
@ -479,11 +497,17 @@ namespace solarApp.Service
|
||||
where powerStationID = @powerStationID and DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d') = @date1
|
||||
group by DATE_FORMAT(`TIMESTAMP`,'%Y-%m-%d');";
|
||||
//conn.Execute(sql, new { powerStationID = _powerStationID, date1 = _date1 });
|
||||
// dt_start2 = DateTime.Now;
|
||||
// duration = DateTime.Now - dt_start2;
|
||||
dt_start2 = DateTime.Now;
|
||||
|
||||
cmd.Parameters.AddWithValue("@powerStationID", _powerStationID);
|
||||
cmd.Parameters.AddWithValue("@date1", _date1);
|
||||
cmd.CommandText = sql;
|
||||
cmd.ExecuteNonQuery();
|
||||
cmd.Parameters.Clear();
|
||||
duration = DateTime.Now - dt_start2;
|
||||
logger.Information($@"sensor step1 INSERT sensoravg_history_day OK duration={duration.TotalSeconds} ");
|
||||
|
||||
//日照計 update
|
||||
sql = string.Empty;
|
||||
|
||||
28
solarApp/Service/testLog.cs
Normal file
28
solarApp/Service/testLog.cs
Normal file
@ -0,0 +1,28 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using Serilog;
|
||||
using static System.Windows.Forms.VisualStyles.VisualStyleElement;
|
||||
|
||||
namespace solarApp.Service
|
||||
{
|
||||
internal class testLog
|
||||
{
|
||||
private ILogger logger = Log.ForContext<testLog>();
|
||||
//private ILogger logger;
|
||||
//public ILogger MyLoger
|
||||
//{
|
||||
// get
|
||||
// {
|
||||
// if (logger == null)
|
||||
// {
|
||||
// logger = Log.ForContext<testLog>();
|
||||
// }
|
||||
// return logger;
|
||||
// }
|
||||
//}
|
||||
public void procOne() {
|
||||
logger.Information("call procOne OK");
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -9,6 +9,8 @@ using System.Text;
|
||||
using System.Windows.Forms;
|
||||
using solarApp.Service;
|
||||
using solarApp.Model;
|
||||
using Serilog;
|
||||
using Serilog.Events;
|
||||
//using System.Text.RegularExpressions;
|
||||
|
||||
namespace solarApp
|
||||
@ -26,6 +28,9 @@ namespace solarApp
|
||||
InitializeComponent();
|
||||
}
|
||||
|
||||
private ILogger logger = Log.ForContext<fmArchive>();
|
||||
|
||||
|
||||
private void bt_inv_proc_Click(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
@ -103,6 +108,7 @@ namespace solarApp
|
||||
f2.Dock = DockStyle.Fill;
|
||||
f2.Show();
|
||||
#endregion
|
||||
logger.Information("start winform process @" + System.DateTime.Now.ToString());
|
||||
}
|
||||
|
||||
private void _timer_Elapsed(object sender, System.Timers.ElapsedEventArgs e)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user