hi, i want log linenumber to my log file, using log4net.the config details of log4net is written programmatically.i tried hell out thing to get line number to be logged but help less,here is my code
private IAppender CreateFileAppender(string name, string fileName) {
PatternLayout layout = new PatternLayout();
//layout.ConversionPattern = "%d{MM/dd/yy HH:mm:ss} %line %-5p : %m%n";
//layout.ConversionPattern = "%d{MM/dd/yy HH:mm:ss} 5p [%t] (%F:%L) - %m%n";
layout.ConversionPattern = "%5p %d{yyyy-MM-dd hh:mm:ss tt} (%c:%L) - [%X {UserIdentityName}] %m%n";
layout.ActivateOptions();
FileAppender appender = new FileAppender(layout, HCVIEWERLOG_FILENAME, true);
appender.Layout = layout;
appender.Name = HCVIEWERLOG_APPENDER;
appender.File = HCVIEWERLOG_FILENAME;
appender.AppendToFile = true;
string[] Args = Environment.CommandLine.Split
("/".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);
foreach(string txt in Args)
appender.Threshold = txt.ToString().ToUpper().Contains("DEBUG") ?
log4net.Core.Level.Debug : log4net.Core.Level.Off;
appender.ActivateOptions();
return (appender as IAppender);
}
even i tried getting line number using stacktrace but im getting the value as 0. here is the code
protected string GetLogMessage(string message) {
StackTrace stackTrace = new StackTrace(true);
StackFrame stackFrame = stackTrace.GetFrame(3);
return (stackFrame.GetMethod().DeclaringType.Name
+ "|" + stackFrame.GetMethod().Name
+ "|" + **stackFrame.GetFileLineNumber()**
+ "||||" + message);
}