Log.Logger = new LoggerConfiguration() .Enrich.FromLogContext() .MinimumLevel.Debug() .MinimumLevel.Override("Microsoft", LogEventLevel.Warning) .Enrich.WithFunction("SystemUserName", () => Environment.UserName) .Enrich.WithFunction("SystemName", () => sysetmName) .Enrich.WithFunction("OSVersion", () => Environment.OSVersion.VersionString) .Enrich.WithFunction("CurrentManagedThreadId", () => Environment.CurrentManagedThreadId.ToString()) .Enrich.WithFunction("CurrentTimeZone", () => TimeZone.CurrentTimeZone.StandardName) // 時間戳 .Enrich.WithFunction("TimeStamp", () => { System.DateTime startTime = TimeZone.CurrentTimeZone.ToLocalTime(new System.DateTime(1970, 1, 1)); // 當地時區 return ((long)(DateTime.Now - startTime).TotalSeconds).ToString(); // 相差秒數 }) .Enrich.WithFunction("LogGuid", () => Guid.NewGuid().ToString("N")) .WriteTo.AmazonS3( new JsonFormatter(), "log.log", "logforservice", Amazon.RegionEndpoint.APNortheast1, "KeyId", "Key", fileSizeLimitBytes: 10, autoUploadEvents: true, rollingInterval: Serilog.Sinks.AmazonS3.RollingInterval.Minute, bucketPath: $"{sysetmName}/{DateTime.Now.Year}/{DateTime.Now.Month}/{DateTime.Now.Day}/{DateTime.Now.Hour}" ) .CreateLogger();
Coding Note
紀錄一下工作上遇到的小問題 可能會有忍不住的碎碎念
2021年3月2日 星期二
Serial Log - Write to AWS Setting
2021年3月1日 星期一
NLOG Setting - write to Sql,File
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.nlog-project.org/schemas/NLog.xsd NLog.xsd"
autoReload="true"
throwExceptions="false"
internalLogLevel="Off" internalLogFile="c:\temp\nlog-internal.log">
<variable name="myvar" value="myvalue"/>
<targets>
<target name="MessageLogFile" xsi:type="File" fileName="C://logs/CampaignFlow/SendMessageLog_${shortdate}.log"
layout="${longdate} | ${level:uppercase=true} | ${message} ${newline}" />
<target name="coloredConsole" xsi:type="ColoredConsole" useDefaultRowHighlightingRules="false"
layout="${longdate}|${pad:padding=5:inner=${level:uppercase=true}}|${message}" >
<highlight-row condition="level == LogLevel.Debug" foregroundColor="DarkGray" />
<highlight-row condition="level == LogLevel.Info" foregroundColor="Gray" />
<highlight-row condition="level == LogLevel.Warn" foregroundColor="Yellow" />
<highlight-row condition="level == LogLevel.Error" foregroundColor="Red" />
<highlight-row condition="level == LogLevel.Fatal" foregroundColor="Red" backgroundColor="White" />
</target>
<target name="tracelogguid" xsi:type="database" connectionstring="${dbconnectionstring}" commandtext="insert into [dbo].[tracelog] 
 ([controller] ,[action] ,[request] ,[response] ,[createtime] ,[issuccess] ,[requestid] ,[exceptionresult],[errorcode],[stringkeyword],[intkeyword],[guidkeyword]) 
 values (@controller, @action, @request, @response, @createtime, @issuccess, @requestid, @exceptionresult,@errorcode,@stringkeyword,@intkeyword,@guidkeyword);">
<parameter name="@controller" layout="${event-properties:item=controller}" />
<parameter name="@action" layout="${event-properties:item=action}" />
<parameter name="@request" layout="${event-properties:item=request}" />
<parameter name="@response" layout="${event-properties:item=response}" />
<parameter name="@createtime" layout="${event-properties:item=createtime}" />
<parameter name="@issuccess" layout="${event-properties:item=issuccess}" />
<parameter name="@requestid" layout="${event-properties:item=requestid}" />
<parameter name="@request" layout="${event-properties:item=request}" />
<parameter name="@errorcode" layout="${event-properties:item=errorcode}" />
<parameter name="@exceptionresult" layout="${exception:tostring}" />
<parameter name="@stringkeyword" layout="${event-properties:item=stringkeyword}" />
<parameter name="@intkeyword" layout="${event-properties:item=intkeyword}" />
<parameter name="@guidkeyword" layout="${event-properties:item=guidkeyword}" />
</target>
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="tracelogguid" />
<logger name="*" levels="Trace,Debug,Warn" writeTo="MessageLogFile,coloredConsole" />
</rules>
</nlog>
2020年5月27日 星期三
[ODA.NET] C# Connect Oracle 9i
目前最推薦的就是利用 Oracle.ManagedDataAccess
但是此套件不支援舊版
所以要連接較舊版本的Oracle可以利用 Oracle.DataAccess.dll
開發工具: Microsoft Visual Studio 2019
資料庫: Oracle9i
1.到Oracle 官網安裝 (以下有傳送門)
要注意版本,如果下載到新版(12.X)會不能用
安裝完成到安裝的資料夾下~\product\11.2.0\client_1\odp.net\bin\4 取出Oracle.DataAccess.dll
再加入專案就完成了
static void Main(string[] args) { string connstring = "Data Source=(DESCRIPTION=(ADDRESS=(PROTOCOL=TCP)(HOST=xxxx)(PORT=xxxx))" + "(CONNECT_DATA=(SERVICE_NAME=xxxx)));User Id=xxxx;Password=xxxx;"; using (OracleConnection conn = new OracleConnection(connstring)) { conn.Open(); string sql = "select * from xxxx where ROWNUM = 1"; using (OracleCommand comm = new OracleCommand(sql, conn)) { using (OracleDataReader rdr = comm.ExecuteReader()) { while (rdr.Read()) { Console.WriteLine(rdr.GetString(0)); } } } } }
參考:
C#連Oracle連線字串
Oracle ODAC with Oracle Developer Tools for Visual Studio
2019年11月29日 星期五
[C#] Lambda All() check ListA all in ListB
public static bool ContainsAll<T>(IEnumerable<T> source, IEnumerable<T> values)
{
return values.All(value => source.Contains(value));
}
2019年11月26日 星期二
新增 net core project
$ dotnet new web -o <專案名稱>
dotnet help 可以查看專案型態的參數
安裝npm $ npm install 檢查npm安裝版本
$ npm -v
init npm
$npm init
如果沒有要設定專案資訊 直接Enter到底
結束之後 會再package.json寫入設定
npm安裝套件 ex jquery
$ npm install jquery
安裝LibMan
$ dotnet tool install -g Microsoft.Web.LibraryManager.Cli
Run
$ dotnet run
Ref microsoft microsoft-SingleR install