M
M
meridbt2020-07-09 16:26:18
.NET
meridbt, 2020-07-09 16:26:18

How to write Cyrillic to file using log4net appender?

Good afternoon, dear colleagues.

The project uses log4net.

There was a need to write an API response to the log, which sends a message in Cyrillic. In response header ContentType = "text/json;charset=utf-8"

using (Stream stream = response.GetResponseStream())
            {
                using (StreamReader reader = new StreamReader(stream))
                {
                    answer = reader.ReadToEnd();
                    Logger.Debug(answer);
                    File.AppendAllText("Logs/msg.txt", answer);
                }
            }


Everything is as it should be in msg.txt:
{"ErrorMessage":"Service not available"}

In the log like this:
2020-07-09 16:16:31,279 DEBUG {"ErrorMessage":"???????????????????????"}

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
d-stream, 2020-07-10
@meridbt

encoding - set, for example, to utf-8 - this is an honest and universal option,
or encode answer in win1251 with possible ambushes when answer arrives, for example, in Estonian)

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question