c# - log4net for WCF REST -
i have written wcf rest service. need enable logging. using log4net nothing logging in database.
i have gone through following links in vain.
- how configure child logger lower loglevel root level in log4net
- log4net in wcf not working
- log4net issue inside wcf
- log4net wcf running service
i using adonetappender. here log4net.config
file.
<appender name="adonetappendermessagelog" type="log4net.appender.adonetappender"> <buffersize value="100" /> <connectiontype value="system.data.sqlclient.sqlconnection, system.data, version=2.0.0.0, culture=neutral, publickeytoken=b77a5c561934e089" /> <connectionstring value="data source=faizan;initial catalog=anasagelogging;integrated security=sspi;" /> <!-- <commandtext value="insert messagelog ([transactionid],[sessionid],[userid],[message],[messagetype],[createddate],[createdby],[applicationid]) values (@transactionid, @sessionid, @userid, @message, @messagetype, @createdtime,@createdby,@applicationid)" />--> <commandtext value="spmessageloginsert" /> <commandtype value="storedprocedure"/> <parameter> <parametername value="@transactionid"/> <dbtype value="string"/> <size value="80"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{transaction_id}"/> </layout> </parameter> <parameter> <parametername value="@sessionid"/> <dbtype value="string"/> <size value="255"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{session_id}"/> </layout> </parameter> <parameter> <parametername value="@userid"/> <dbtype value="string"/> <size value="80"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{user_id}"/> </layout> </parameter> <parameter> <parametername value="@message"/> <dbtype value="string"/> <size value="10000"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{message}"/> </layout> </parameter> <parameter> <parametername value="@messagetype"/> <dbtype value="string"/> <size value="255"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{message_type}"/> </layout> </parameter> <parameter> <parametername value="@createdtime"/> <dbtype value="datetime"/> <layout type="log4net.layout.rawtimestamplayout"/> </parameter> <parameter> <parametername value="@createdby"/> <dbtype value="string"/> <size value="255"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{created_by}"/> </layout> </parameter> <parameter> <parametername value="@applicationid"/> <dbtype value="string"/> <size value="255"/> <layout type="log4net.layout.patternlayout"> <conversionpattern value="%property{application_id}"/> </layout> </parameter> </appender>
here how using it.
static log4net.util.logicalthreadcontextproperties properties = log4net.logicalthreadcontext.properties; private static log4net.ilog log { get; set; } public static void write( object session_id, object user_id, object message, object message_type, object created_by, object msg) { properties["session_id"] = session_id; properties["user_id"] = user_id; properties["message"] = message; properties["message_type"] = message_type; properties["created_by"] = created_by; log.info(msg); }
note: wrapper class function. every thing working fine, no exception thrown. when see database table, empty. testing on local machine not on production. don't know missing. appreciated.
thanks
Comments
Post a Comment