HELP! Tab delimited headers AND Messages

classic Classic list List threaded Threaded
5 messages Options
Reply | Threaded
Open this post in threaded view
|

HELP! Tab delimited headers AND Messages

Mike Curtis
Hello,

I need NLog to print out the headers in a tab delimited style without quotes around them.

Now I get this:

2006-07-25 17:42:59.1477 "EmbeddedType LogType UserID Message EMessage SystemID"

What I need is 2006-07-25 17:42:59.1477 EmbeddedType LogType UserID Message EMessage SystemID

The message I get with the Log method comes out like:

"0 Batch mcurtis Protocol 'New Protocol 1' Deleted MCURTIS-XP"

I need this without the quotes around the string. It appears that if I insert any kind of tab character I end up with quotes around the string. If I use spaces I get no quotes but I have no tabs delimiting either.

It appears that the ${message} along with the

logger.Debug(anotherString); or

logger.Log(LogLevel.Debug, theLogString);

results in quotes around the message with tabs inside.

I'd like the quotes gone. Any thoughts?

Mike
Reply | Threaded
Open this post in threaded view
|

Re: HELP! Tab delimited headers AND Messages

Jarek Kowalski
Administrator
Please post your configuration file here. Without it we're not able to help you.
NLog Blog
Reply | Threaded
Open this post in threaded view
|

Re: HELP! Tab delimited headers AND Messages

Mike Curtis
Thanks. I'm doing this programmically -->

internal void CreateSystemLogFile()
{
            // Create the System Log file
            CsvFileTarget systemLogger  = new CsvFileTarget();
            // Make the delimiter a tab character
            systemLogger.Delimiter = CsvFileTarget.ColumnDelimiterMode.Tab;

            // Create the name of the file as SystemLog.DATE.log
            string theDateString;

            int seconds = DateTime.Now.Second;
            int minutes = DateTime.Now.Minute;
            int hour = DateTime.Now.Hour;
            int days = DateTime.Now.Day;
            int month = DateTime.Now.Month;
            int year = DateTime.Now.Year;

            string sYear = year.ToString();
            string sMonth = month.ToString();
            string sDays = days.ToString();
            string sHours = hour.ToString();
            string sMinutes = minutes.ToString();
            string sSeconds = seconds.ToString();

            theDateString = sYear + sMonth + sDays + sHours + sMinutes + sSeconds;

            systemLogger.FileName = SystemLogFilePath + "\\SystemLog" + theDateString + ".log";
            systemLogger.KeepFileOpen = true;
            systemLogger.Columns.Add(new CsvFileColumn("time", "${longdate}"));
            systemLogger.Columns.Add(new CsvFileColumn("message", "${message}"));
           
            NLog.Config.SimpleConfigurator.ConfigureForTargetLogging(systemLogger, LogLevel.Debug);

            systemLogger.Name = "LuminexSystemLog";

            logger = LogManager.GetLogger("LuminexSystemLog"); // Logger Type

This is the attempt to print a header to the file. The result is a tab delimited string with quotes around it. I'd like to get rid of the quotes.

            string theLogString = "EmbeddedType\tLogType\tUserID\tMessage\tEMessage\tSystemID";

            logger.Log(LogLevel.Debug, theLogString);
}

The file called:


public void AddSystemLogMessage(SystemLogMessage systemLog, User overrideUser)
        {
            //MSCTODO Fix this for nlog
            logger = LogManager.GetLogger("LuminexSystemLog"); // Logger Type

Putting spaces in the thring results in a string to log file without quotes around it. Of course I need the tabs.

            //string theLogString = systemLog.EmbeddedType.ToString();
            //theLogString += "                ";
            //theLogString += systemLog.LogType.ToString();
            //theLogString += "        ";
            //theLogString += systemLog.UserID;
            //theLogString += "  ";
            //theLogString += systemLog.Message;
            //theLogString += "  ";
            //theLogString += systemLog.EmbeddedMessage;
            //theLogString += "            ";
            //theLogString += systemLog.SystemID;

Both these versions result in strings around the information that is tabbed. Exell doesn't like the quotes so everything ends up in one cell.

            string[] sbarray = new string[6] {
                systemLog.EmbeddedType.ToString(),
                systemLog.LogType.ToString(),
                systemLog.UserID,
                systemLog.Message,
                systemLog.EmbeddedMessage,
                systemLog.SystemID
            };

            string delimitedInfo = string.Join("\t", sbarray);

            /*
            StringBuilder theLogString2 = new StringBuilder();
            theLogString2.Append(systemLog.EmbeddedType.ToString());
            theLogString2.AppendFormat("\t");
            theLogString2.Append(systemLog.LogType.ToString());
            theLogString2.AppendFormat("\t");
            theLogString2.Append(systemLog.UserID);
            theLogString2.AppendFormat("\t");
            theLogString2.Append( systemLog.Message );
            theLogString2.AppendFormat("\t");
            theLogString2.Append(systemLog.EmbeddedMessage);
            theLogString2.AppendFormat("\t");
            theLogString2.Append(systemLog.SystemID);
            */

            //logger.Log(LogLevel.Debug, theLogString);
            logger.Log(LogLevel.Debug, delimitedInfo);
            //logger.Log(LogLevel.Debug, theLogString2);
}

So this is the real issue. I need a log file that I can drop into excel so the data on each line can't have quotes around the whole line.

Thanks for responding so quickly.

Mike
Reply | Threaded
Open this post in threaded view
|

Re: HELP! Tab delimited headers AND Messages

Mike Curtis
I found the issue. Duh.

I added this line:

systemLogger.Quoting = CsvQuotingMode.Nothing; // no Quoting

This stopped the problem.

Mike

Reply | Threaded
Open this post in threaded view
|

Re: HELP! Tab delimited headers AND Messages

Jarek Kowalski
Administrator
This might be the temporary fix, but I'm working on proper support for headers and footers, so you might be required to change some of your code when NLog 1.0 RC2 is released.

In particular CvsFileTarget will be removed and will be replaced with a combination of FileTarget + CvsLayout.
NLog Blog