tags:

views:

29

answers:

2

Dear ladies and sirs.

My need is simple - I want to be able to open my text log file in excel, so that it automatically breaks it in columns matching the log fields.

For that, I need the log fields separated with a tab.

My pattern is: %utcdate [%thread] %-5level %logger - %message%newline

I need something like: %utcdate%tab[%thread]%tab%-5level%tab%logger%tab%message%newline

Thanks.

A: 

If this is just about Excel then you could use some other separator, maybe even a ; would be good enough.

Another option would be to write your own pattern converter. An example can be found here.

Stefan Egli
Nope, this is not only for excel. The file should remain human readable.
mark
Then go for option 2. As far as I can tell log4net is currently not able to do what you want.
Stefan Egli
+1  A: 

Caveat: I haven't actually used log4net. But if I understand correctly, the configuration is an XML file, isn't it? And the pattern is just text with some special tokens. So have you tried embedding actual tab characters in your pattern? The XML sequence for a tab is 	, e.g.:

<conversionPattern value="%utcdate&#9;[%thread]&#9;%-5level&#9;%logger&#9;%message%newline" />

Or if you're supplying the pattern some other way (perhaps via the PatternString constructor or whatever), just include tab characters in the string you're passing in. The docs for that constructor defer to the PatternLayout docs to talk about the string itself, and there they say:

You are free to insert any literal text within the conversion pattern.

(Their emphasis.) Worth a try, anyway...

T.J. Crowder
Thanks. \t does not work, but works indeed.
mark
@mark: Good deal, glad that helped.
T.J. Crowder