C # program A sends log records to program B, program B processes and parses log records
Keywords: C #; Log record; online log record; Socket;httplistener
First, the common scene
1, app development, in the real machine or virtual machine run by H5 or Apicloud program, or debugging someone else to write the program, often can not see a piece of code after the output of the implementation of what. As a person to deal with the background every day, the browser is especially accustomed to Google's F12 Console.log, but also hope that the app debugging will be able to view the output in real time.
2, development of a. NET website, or Java Web site, when debugging, wrote a lot of System.console.writeline code, wrote a lot of System.out.println code, but the site released, in addition to writing in the file/database inside the log records, If there is a problem, you cannot locate the code error. Write the error in the file, but also worry about the file is too large, occupy disk space, want to have a can be opened on the log log, close does not log log tool.
2, other similar situation, one is the program is developed in a black box, or do not want to write useless log to disk occupy space, you need an open ready, close stop tool
Summary: I named him: Visualtools, a visual display tool for log records.
Second, the basic structure process design diagram:
As shown in: The Visual Debug tool provides two ways that an application sends a log message directly to the Visual debug tool, the other is that the application sends a GET request to the HTTP server, and an HTTP server relays a log message to the visual Tool, both ways, personal recommendation second, the second kind of extensibility and compatibility are good, as long as the application simulates sending a GET request, and putting the data into parameters can be done.
The second approach has the advantage that it is not a program on the same machine that can log logs by accessing the HTTP server, which is especially handy for app segment output field values.
Third, the introduction of software:
1, HTTP Server mini HTTP tool, used to proxy forward the log message:
The application is accessed via get: http://127.0.0.1:8081?pid=&msgLevel=&msg=&other=
The way to send a log message.
Tips:
JS Call Mode:
function Getlogpage(pid,msglevel,msg,otherinfo) {
$. Get("http://127.0.0.1:8081?pid="+encodeuricomponent(pid) +"&msglevel=" +encodeuricomponent(msglevel) +"&msg="+encodeuricomponent(msg ) +"&other="+encodeuricomponent(otherinfo), function (response,status,xhr) {
Console.log(response);
});
}
C # Http of the Get call Way, self-Baidu.
C # call method, sent directly to Visual Debug Tool : (Related classes, open source, with open source address)
Toolslib. msgentity msgentity = new toolslib. Msgentity();
Msgentity. Msglevel = msglevel;
Msgentity. msg = msg;
Msgentity. Timestr = timestr;
Msgentity. Pidindentity = pidindentity;
Msgentity. Other = other;
string ret = toolslib. Sendmsgtobs. Send(msgentity);// sending entity
2. Visual Debug Tool Tools
Note: The HTTP Server mini HTTP tool and the Visual Debug tool must be running on the same server side. If you want to use another computer access, you can set the program as a server in the Visual Debug tool, and other machines connect by choosing to connect to the server.
If you want source code, contact qq:1097712982
Program address (source not included): Https://files.cnblogs.com/files/lijuanfei/VisualDebugTool.rar
C # program A sends log records to program B, program B processes and parses log records