Template的內容控制項後面如果是接換行符號,不可以用 ↓(Shift+Enter),要用←┘(Enter)
不然替代文字後產生出的文件會有格式問題
2015年8月7日
2015年7月31日
Log4Net 學習紀錄
1.NuGet install log4net
2.Cerate file log4net.config
儲存GUID
Trace log4net debug message by modify web.config
2.Cerate file log4net.config
<configuration>
<configSections>
<section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net"/>
</configSections>
</configuration>
<configuration>
<!--logger: 記錄器,可自訂設定屬性(可多個)-->
<!--appender-ref: 指定參考的Appender設定-->
<logger name="Rolling">
<appender-ref ref="RollingFile" />
</logger>
<logger name="DB">
<appender-ref ref="LogDatabase" />
</logger>
</configuration>
<configuration>
<!--root logger: 根記錄器,當其他記錄器執行完後最後會執行根記錄器(唯一)-->
<!--level: 記錄級別設定-->
<root>
<level value="DEBUG" />
<appender-ref ref="RollingFile" />
</root>
</configuration>
For File
<configuration>
<!--appender: 內容為輸出格式的設定-->
<!--type: 輸出類型,例如 ConsoleAppender 為主控台輸出、RollingFileAppender 為文字檔輸出-->
<!--file: 輸出檔案的路徑位置-->
<!--layout: 記錄的格式設定-->
<appender name="RollingFile" type="log4net.Appender.RollingFileAppender">
<file value="C:\Log\PlayLog.txt" />
<appendToFile value="true" />
<maximumFileSize value="1000KB" />
<maxSizeRollBackups value="2" />
<rollingStyle value="Date" />
<datePattern value="yyyyMMdd" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="[Activity]%newlineActivityId: %property{GUID}%newlineTime: %date{yyyy-MM-dd HH:mm:ss}%newlineLevel: %level%newline%newline[System]%newlineSystem: %property{System}%newline%newline[IP]%newlineServerIP: %property{ServerIP}%newlineClientIP: %property{ClientIP}%newline%newline[Message]%newlineDescription: %property{Description}%newlineException: %property{Exception}%newline%newline[Properties]%newline%message%newline%newline" />
</layout>
</appender>
</configuration>
For DB
<configuration>
<appender name="LogDatabase" type="log4net.Appender.AdoNetAppender">
<bufferSize value="100" />
<connectionType value="System.Data.SqlClient.SqlConnection, System.Data, Version=4.0.0.0, Culture=Neutral, PublicKeyToken=b77a5c561934e089" />
<connectionString value="Data Source={Server};Initial Catalog={DBName};User ID={UserID};Password={Password}" />
<commandText value="INSERT INTO [dbo].[Message] (MessageId, Message) VALUES (@MessageId, @Message)" />
<parameter>
<parameterName value="@MessageId" />
<dbType value="Int32" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{MessageId}" />
</layout>
</parameter>
<parameter>
<parameterName value="@Message" />
<dbType value="String" />
<size value="100" />
<layout type="log4net.Layout.PatternLayout">
<conversionPattern value="%property{Message}" />
</layout>
</parameter>
</appender>
</configuration>
3.Add Watch in Global.asax Application_Start()log4net.Config.XmlConfigurator.ConfigureAndWatch(new System.IO.FileInfo(Server.MapPath("~/log4net.config")));
儲存GUID
log4net.ThreadContext.Properties["GUID"] = guidValue;
<parameter>
<parameterName value="@LogId" />
<dbType value="Guid" />
<layout type="log4net.Layout.RawPropertyLayout">
<key value="GUID" />
</layout>
</parameter>
Trace log4net debug message by modify web.config
<configuration>
<appSettings>
<add key="log4net.Internal.Debug" value="true"/>
</appSettings>
</configuration>
<configuration>
<system.diagnostics>
<trace autoflush="true">
<listeners>
<add name="textWriterTraceListener"
type="System.Diagnostics.TextWriterTraceListener"
initializeData="C:\Log\log4net.txt"
/>
</listeners>
</trace>
</system.diagnostics>
</configuration>
2015年7月28日
2015年5月14日
繳費疑雲
一個帳號前後有兩個擁有者A,B
A把帳號讓渡給B了
B去查帳單的時候,A、B的兩個時期的帳單都有
B把所有帳單都繳掉了
這時查繳費紀錄只會出現B的資料
A去查繳費紀錄時就查不到了
user卻想在繳費紀錄看到“誰產生帳單的”
A把帳號讓渡給B了
B去查帳單的時候,A、B的兩個時期的帳單都有
B把所有帳單都繳掉了
這時查繳費紀錄只會出現B的資料
A去查繳費紀錄時就查不到了
user卻想在繳費紀錄看到“誰產生帳單的”
2015年4月20日
2015年4月17日
foreach 物件屬性
foreach (PropertyInfo property in obj.GetType().GetProperties())
{
if (property.GetValue(obj, null) != null)
{
property.SetValue(obj, "");
}
}
2015年4月1日
前端頁面使用者操作紀錄
在遠通的專案,發生了 end-user在 CSS系統繳費,說是只繳兩筆,但是系統銷帳卻有三筆的狀況
但是因為沒有頁面元件操作紀錄,所以死無對証
解決的方法可以考慮在 checkbox綁 onclick,每按一下就紀錄下來,submit的時候一併送出,再寫入 log
但是因為沒有頁面元件操作紀錄,所以死無對証
解決的方法可以考慮在 checkbox綁 onclick,每按一下就紀錄下來,submit的時候一併送出,再寫入 log
2015年3月31日
.NET SqlParameter(string paraName, object value) 字串 NVarchar
最近程式再被調教中
收到一封 mail說我們的 SQL script都是用 nvarchar,效能較差
要我們改成 varchar
查了一下是因為底層的 function寫得太便利,大家都是丟 object[] 進去直接賦值 大概是像這樣子
如果 value是 int、dobule、datetime等都沒問題,產生出來的 SqlParameter內的屬性 SqlDbType會自動轉成對應的類別
但如果是字串,不管是 string、String還是 char,一律會被轉成 nvarchar
問題就來了
因為 table schema是放 varchar,query script的 where條件被轉成 nvarchar,就會導致效能變差~
收到一封 mail說我們的 SQL script都是用 nvarchar,效能較差
要我們改成 varchar
查了一下是因為底層的 function寫得太便利,大家都是丟 object[] 進去直接賦值 大概是像這樣子
SqlParameter sqlPara = new SqlParameter("@" + temp[0], paraValues[i]);
如果 value是 int、dobule、datetime等都沒問題,產生出來的 SqlParameter內的屬性 SqlDbType會自動轉成對應的類別
但如果是字串,不管是 string、String還是 char,一律會被轉成 nvarchar
問題就來了
因為 table schema是放 varchar,query script的 where條件被轉成 nvarchar,就會導致效能變差~
2015年3月20日
Java的 milliseconds 轉成 c#的 DateTime
long javaMilliSec = 1386862447000;
new DateTime(1970,1,1,0,0,0,DateTimeKind.Utc).Add(new TimeSpan(javaMilliSec *TimeSpan.TicksPerMillisecond)).ToString("yyyy/MM/dd HH:mm:ss")
ref: Get c# DateTime from Java System.currentTimeMillis
2015年2月6日
2014年11月20日
Can not find "Aspose.Cells.lic"
在用 .NET MVC做 ReportViewer的 PDF/Excel 輸出浮水印時
發生 OBSR環境的 Excel產出有 error (0 byte)
查到 log是寫 Can not find "Aspose.Cells.lic" ...
看了一下 OBSR跟 SIT01的佈置
OBSR的資料夾底下有放 "Aspose.Cells.lic",SIT01沒有
但是 SIT01沒問題反而是 OBSR有問題??
最後發現是 OBSR Aspose.Cells.lic檔案的屬性 Build Action沒有改成 Embedded Resource
問題找到了,收工!
ref:
2014年10月2日
json轉 GUID字串檢核格式不嚴謹
foreach (object obj in args)
{
if (obj == null)//需過濾參數=null
{
continue;
}
else if (obj.ToString().Length == 38 && obj.ToString().IndexOf("-", 0, 10) == 9)
{
activityId = JsonConvert.DeserializeObject<guid>(obj.ToString());
break;
}
else if (obj.ToString().Length == 36 && obj.ToString().IndexOf("-", 0, 10) == 8)
{
activityId = Guid.Parse(obj.ToString());
break;
}
}
然後人家輸入一個剛好長度 38的字串,第一個 - 又剛好在第十個字元 就死了
原本我是想到用 regular expression做檢核
想了一串的 regex
Regex regGuid = new Regex("[{(]?[a-zA-Z0-9]{8}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[a-zA-Z0-9]{4}-[]{12}[})]?");
後來看到別人提供的做法
foreach (object obj in args)
{
if (obj == null)
{
continue;
}
else if (Guid.TryParse(obj.ToString(), out activityId))
{
break;
}
}
只是要注意 tryparse失敗的話 guid會被填成 Guid.Empty
2014年7月15日
解決 Visual Studio載入時發生錯誤 您必須在使用系統管理員帳戶的環境中執行Visual Studio,才能 ... blahblah
因為 Url已經在 IIS被綁定
所以需要移除 binding
開啟 powershell執行以下程式碼(或以記事本存成 .ps1檔案後執行)
所以需要移除 binding
開啟 powershell執行以下程式碼(或以記事本存成 .ps1檔案後執行)
$appCmd = "C:\Program Files (x86)\IIS Express\appcmd.exe"
$result = Invoke-Command -Command {& $appCmd 'list' 'sites' '/text:SITE.NAME' }
for ($i=0; $i -lt $result.length; $i++)
{
Invoke-Command -Command {& $appCmd 'delete' 'site' $result[$i] }
}
如果有註冊表問題,依照提示訊息至 regedit修改