I use log4net along with ElasticSearch and Kibana. Now my web.config looks like this:
<log4net> <appender name="ElasticSearchAppender" type="log4net.ElasticSearch.ElasticSearchAppender, log4net.ElasticSearch"> <layout type="log4net.Layout.PatternLayout,log4net"> <param name="ConversionPattern" value="%date - %level - %message %property{location} %property{label} %property{mstimeload} %property{applicationid} %property{page} %property{ipclient} %property{browser} %property{browsersignature} %property{appversion} %property{sessionuniquecodetag} %property{globalcountertailsloaded} %property{ipserveraddress} %newline" /> </layout> <connectionString value="Server=myip;Index=logstash;Port=9200;rolling=true"/> <lossy value="true" /> <bufferSize value="100" /> <evaluator type="log4net.Core.LevelEvaluator"> <threshold value="ERROR"/> </evaluator> </appender> <root> <level value="ALL"/> <appender-ref ref="ElasticSearchAppender" /> </root>
I have some user parameters like location, label, mstimeload, applicationid, page, ipclient, ... Everything works fine, but all these parameters are of type string , instead I would like to have type integer or geo_point , but I donβt I know how to tell log4net from which type is my parameter. Then in C # I write my log as follows:
private static readonly log4net.ILog log = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType); log4net.ThreadContext.Properties["label"] = label; log4net.ThreadContext.Properties["ipclient"] = ipaddress; log4net.ThreadContext.Properties["browser"] = browserType; log4net.ThreadContext.Properties["browsersignature"] = browserHashSignature; log4net.ThreadContext.Properties["appversion"] = ASSettings.ApplicationVersion; log4net.ThreadContext.Properties["mstimeload"] = msTime == null ? null : Convert.ToString(Convert.ToInt32(msTime.Value), CultureInfo.InvariantCulture); log4net.ThreadContext.Properties["globalcountertailsloaded"] = globalCounter_tilesloaded == null ? null : Convert.ToString(globalCounter_tilesloaded.Value, CultureInfo.InvariantCulture); log4net.ThreadContext.Properties["ipserveraddress"] = ipserveraddress; log4net.ThreadContext.Properties["page"] = page; log4net.ThreadContext.Properties["sessionuniquecodetag"] = sessionuniquecodetag; log4net.ThreadContext.Properties["applicationid"] = applicationid; log4net.ThreadContext.Properties["location"] = ASSecurity.GetLatLongFromIp(ipaddress); log.Error(description, ex);
But I'm not sure if this is the best way to do this, or if there are other ways.
source share