2009년 9월 10일 목요일

log4net 세팅

0. 다운로드

http://logging.apache.org/log4net/download.html

 

1. log4net.dll 참조

 

2. app.config 설정

App 인경우 console or file mode

서비스중인경우 database mode로 세팅하면 좋을듯

 

   1: <?xml version="1.0" encoding="utf-8" ?>
   2: <configuration>
   3:     <configSections>
   4:         <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
   5:     </configSections>
   6:  
   7:     <log4net>
   8:         <appender name="Console" type="log4net.Appender.ConsoleAppender">
   9:             <layout type="log4net.Layout.PatternLayout">
  10:                 <conversionPattern value="%d [%t] %-5p %c.%M - %m%n" />
  11:             </layout>
  12:         </appender>
  13:  
  14:         <appender name="RollingFileAppender" type="log4net.Appender.RollingFileAppender">
  15:             <file value="../../../logs/log.txt" />
  16:             <appendToFile value="true" />
  17:             <rollingStyle value="Size" />
  18:             <maxSizeRollBackups value="3" />
  19:             <maximumFileSize value="100KB" />
  20:             <staticLogFileName value="true" />
  21:             <layout type="log4net.Layout.PatternLayout">
  22:                 <conversionPattern value="%d [%t] %-5p %c.%M - %m%n" />
  23:             </layout>
  24:         </appender>
  25:  
  26:         <appender name="AdoNetAppender" type="log4net.Appender.AdoNetAppender">
  27:             <bufferSize value="1" />
  28:             <connectionType value="System.Data.SqlClient.SqlConnection, System.Data , Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
  29:             <connectionString value="server=192.168.0.100;database=fundstore;user id=sa;password=zhemfjtnl!1" />
  30:             <commandText value="INSERT INTO [Log4net] ([Date],[Thread],[Level],[Logger],[Message],[Exception]) VALUES (@log_date, @thread, @log_level, @logger, @message, @exception)" />
  31:             <parameter>
  32:                 <parameterName value="@log_date" />
  33:                 <dbType value="DateTime" />
  34:                 <layout type="log4net.Layout.RawTimeStampLayout" />
  35:             </parameter>
  36:             <parameter>
  37:                 <parameterName value="@thread" />
  38:                 <dbType value="String" />
  39:                 <size value="255" />
  40:                 <layout type="log4net.Layout.PatternLayout">
  41:                     <conversionPattern value="%thread" />
  42:                 </layout>
  43:             </parameter>
  44:             <parameter>
  45:                 <parameterName value="@log_level" />
  46:                 <dbType value="String" />
  47:                 <size value="50" />
  48:                 <layout type="log4net.Layout.PatternLayout">
  49:                     <conversionPattern value="%level" />
  50:                 </layout>
  51:             </parameter>
  52:             <parameter>
  53:                 <parameterName value="@logger" />
  54:                 <dbType value="String" />
  55:                 <size value="255" />
  56:                 <layout type="log4net.Layout.PatternLayout">
  57:                     <conversionPattern value="%logger" />
  58:                 </layout>
  59:             </parameter>
  60:             <parameter>
  61:                 <parameterName value="@message" />
  62:                 <dbType value="String" />
  63:                 <size value="4000" />
  64:                 <layout type="log4net.Layout.PatternLayout">
  65:                     <conversionPattern value="%message" />
  66:                 </layout>
  67:             </parameter>
  68:             <parameter>
  69:                 <parameterName value="@exception" />
  70:                 <dbType value="String" />
  71:                 <size value="2000" />
  72:                 <layout type="log4net.Layout.ExceptionLayout" />
  73:             </parameter>
  74:         </appender>
  75:  
  76:  
  77:         <root>
  78:             <level value="DEBUG" />
  79:             <appender-ref ref="RollingFileAppender"/>
  80:             <appender-ref ref="Console"/>
  81:             <!--appender-ref ref="AdoNetAppender" /-->
  82:         </root>
  83:     </log4net>
  84: </configuration>

3. 초기화

app 인경우 program.cs 에 web 인경우 global application_start 쯤에

다음코드를 넣는다.

   1: using log4net.Config;
   2:  
   3:     static class Program {
   4:         [STAThread]
   5:         static void Main() {
   6:             XmlConfigurator.Configure();

 

3-1. instance

 

   1: using log4net;
   2:  
   3:     public class Test {
   4:         private ILog log = LogManager.GetLogger(typeof(Test));

 

 

* log4net 을 참조하고 빌드하면,

5메가짜리 System.Web.dll 과 1메가짜리 log4net.xml 이 같이 생성된다.

WM에서는 무시할수 없는 크기인듯....

 

 

 

 

 

 

 

2009년 9월 4일 금요일

Nike+ Workflow

image

내 iPod nano에 있는 Nike+iPod의 workflow. 필요해서 대강 그린거.

2009년 9월 3일 목요일

GPS NMEA sentence

0. 참고

구문 정리가 잘 되어 있음 : http://aprs.gids.nl/nmea/

구현예제(JAVA) : http://developers.sun.com/mobility/apis/articles/bluetooth_gps/part2/#1

 

1. 종류

 * 하이라이트 된 항목 말고는 어따 써야할지 감이 안옴.

 

   $GPBOD - Bearing, origin to destination
   $GPBWC - Bearing and distance to waypoint, great circle
   $GPGGA - Global Positioning System Fix Data
   $GPGLL - Geographic position, latitude / longitude
   $GPGSA - GPS DOP and active satellites
   $GPGSV - GPS Satellites in view
   $GPHDT - Heading, True
   $GPR00 - List of waypoints in currently active route
   $GPRMA - Recommended minimum specific Loran-C data
   $GPRMB - Recommended minimum navigation info
   $GPRMC - Recommended minimum specific GPS/Transit data
   $GPRTE - Routes
   $GPTRF - Transit Fix Data
   $GPSTN - Multiple Data ID
   $GPVBW - Dual Ground / Water Speed
   $GPVTG - Track made good and ground speed
   $GPWPL - Waypoint location
   $GPXTE - Cross-track error, Measured
   $GPZDA - Date & Time

2. 활용

 2-1. 위도,경도 : $GPGGA or $GPRMC

 2-2. 고도 : $GPGGA

 2-3. 속도 : $GPVTG

 

3. 상세설명

 3-1. $GPGGA

 

$GPGGA,hhmmss.ss,llll.ll,a,yyyyy.yy,a,x,xx,x.x,x.x,M,x.x,M,x.x,xxxx

hhmmss.ss = UTC of position
llll.ll = latitude of position
a = N or S
yyyyy.yy = Longitude of position
a = E or W
x = GPS Quality indicator (0=no fix, 1=GPS fix, 2=Dif. GPS fix)
xx = number of satellites in use
x.x = horizontal dilution of precision
x.x = Antenna altitude above mean-sea-level
M = units of antenna altitude, meters

x.x = Geoidal separation
M = units of geoidal separation, meters
x.x = Age of Differential GPS data (seconds)
xxxx = Differential reference station ID


 3-2. $GPRMC

 

$GPRMC,225446,A,4916.45,N,12311.12,W,000.5,054.7,191194,020.3,E*68

225446       Time of fix 22:54:46 UTC
A            Navigation receiver warning A = OK, V = warning
4916.45,N    Latitude 49 deg. 16.45 min North
12311.12,W   Longitude 123 deg. 11.12 min West

000.5        Speed over ground, Knots
054.7        Course Made Good, True
191194       Date of fix  19 November 1994
020.3,E      Magnetic variation 20.3 deg East
*68          mandatory checksum


 3-3. $GPVTG

 

$GPVTG,054.7,T,034.4,M,005.5,N,010.2,K

054.7,T      True track made good
034.4,M      Magnetic track made good
005.5,N      Ground speed, knots
010.2,K      Ground speed, Kilometers per hour


4. 적용예(C#)

   1: public void ParseGPGGA( string rawData ) {
   2:     int start = rawData.IndexOf("$GPGGA");
   3:     int end = rawData.IndexOf("*", start);
   4:     string gprmc = rawData.Substring(start + 6, end);
   5:  
   6:     string[] vals = gprmc.Split(delimiter);
   7:  
   8:     //this.Latitude = vals[3] + " " + vals[2];
   9:     //this.Longitude = vals[5] + " " + vals[4];
  10:     this.Latitude = Convert.ToDouble(vals[2]);
  11:     this.Longitude = Convert.ToDouble(vals[4]);
  12:     this.Altitude = Convert.ToDouble(vals[9]);            
  13: }
  14:  
  15: public void ParseGPVTG(string rawData) {
  16:     int start = rawData.IndexOf("$GPVTG");
  17:     int end = rawData.IndexOf("*", start);
  18:     string gpvtg = rawData.Substring(start + 6, end);
  19:  
  20:     string[] vals = gpvtg.Split(delimiter);
  21:  
  22:     this.Speed = Convert.ToDouble(vals[7]);            
  23: }

 

2009년 9월 1일 화요일

visual studio 2008 + windows mobile 에서 SQLite 사용

0. 참고

 다운로드 : http://sqlite.phxsoftware.com/

 SQLite.dll : http://www.sqlite.org/

 

1. 세팅

System.Data.SQLite.dll 참조하고,

배포시에 SQLite.Interop.<version?>.dll 을 수동 배포해준다.

windows mobile 에서 사용할경우(특히 emulator)

SQLite.Interop.dll은 자동 배포되지 않으므로,

"visual studio remote tool - remote file viewer"

를 통해 SQLite.Interop.dll을 복사해준다.

 

2. 사용샘플코드

   1: using System.Reflection;
   2: using System.Diagnostics;
   3: using System.IO;
   4: using System.Data.SQLite;
   5:  
   6: 
   7:     public class Store {
   8:  
   9:         public Store() {
  10:             this.Install();
  11:         }
  12:  
  13:         string FileName{
  14:             get {
  15:                 string root = Path.GetDirectoryName(Assembly.GetExecutingAssembly().GetModules()[0].FullyQualifiedName);
  16:                 string fileName = Path.Combine(root, "tet.s3db");
  17:                 return fileName;
  18:             }            
  19:         }
  20:  
  21:         void Install() {
  22:             if (!File.Exists(this.FileName)) {
  23:                 SQLiteConnection.CreateFile(this.FileName);
  24:                 string sql = "create table log(userId varchar(30) , latitude float, longitude float, altitude float , speed float , regdate date);";
  25:                 using (SQLiteConnection con = new SQLiteConnection(string.Format("Data Source={0}", this.FileName))) {
  26:  
  27:                     using (SQLiteCommand cmd = new SQLiteCommand(con)) {
  28:                         cmd.CommandText = sql;
  29:  
  30:                         con.Open();
  31:                         cmd.ExecuteNonQuery();
  32:                         con.Close();
  33:                     }
  34:                 }
  35:             }
  36:         }
  37:  
  38:         public void Add(string userId, double latitude, double longitude, double altitude , double speed) {
  39:             string sql = string.Format(
  40:                 "insert into log(userId ,latitude , longitude , altitude , speed , regdate) values('{0}',{1},{2},{3},{4},datetime('now'))"
  41:                 , userId, latitude, longitude, altitude, speed);
  42:             using (SQLiteConnection con = new SQLiteConnection(string.Format("Data Source={0}", this.FileName))) {
  43:                 using (SQLiteCommand cmd = new SQLiteCommand(con)) {
  44:                     cmd.CommandText = sql;
  45:                     con.Open();
  46:                     cmd.ExecuteNonQuery();
  47:                     con.Close();
  48:                 }
  49:             }                        
  50:         }