经常有人问为什么运行服务器, 黑黑的控制台为什么没有任何输出, 不知道是不是启动成功了.
为什么不输出Log在控制台的原因如下:
熊猫:
repl提交了,爽翻天,以后运行时,想看什么数据就看什么数据,直接在Console中打印就行了
加了repl后,取消了log在控制台显示, Log太影响输入了
服务器开发最麻烦的就是,服务器的数据是个黑盒子。之前我是用reload执行一段代码的形式来打印数据,还是有点麻烦,现在有了repl,服务器的数据就完全是透明的了,太太太太太方便了!之前只有动态语言能做到,C#居然也能
熊猫: 找到非常简单加载dll的方式了#r "D:\Source\ET\Bin\Hotfix.dll"这样可以在repl中加载Hotfix.dll,不过还是会锁死Hotfix.dll这个文件,慎用! 还没找到解锁的方法
其实还是难用,主要满足一些用户的习惯,直接改代码reload不香吗?
需要注意:
客户端不能用
可以随时的打印一些内存状态
除了查询, 还能执行某些逻辑
在上线后看下代码可以自己做工具使用
linux下也可以用
上下文 , 需要带上命名空间
进入repl没有智能补全, 全手敲过于硬核了.
举个栗子:
可以在IDE中写好复制过去.
不建议生成环境上开此功能,万一输错就GG了
上线后不建议用console组件
- 千万别养成坏习惯,永远不要用控制台,控制台极其影响性能。Linux上还会把整个进程阻塞掉
- 线上用NLOG,要配置成async,还要设置buffer size。绝对不要用的console这个类,危害巨大。
- 上线后,注释掉就对了,那玩意可以直接干满你的服务器磁盘,内存泄露等问题。
https://et-framework.cn/d/190-console
NLog如何才能开启输出在控制台?
配置NLog, 复制以下代码黏贴到 \ET\Server\App\NLog.config
中.
替换了log配置之后重新编译一下.配置文件不会引发编译
<?xml version="1.0" encoding="utf-8" ?>
<nlog xmlns="http://www.nlog-project.org/schemas/NLog.xsd" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<variable name="appType" value="" />
<variable name="appId" value="" />
<targets>
<target name="all" xsi:type="File"
fileName="${basedir}/../Logs/Log.txt"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
</targets>
<targets>
<target name="trace" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Trace/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
<target name="traceConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
</targets>
<targets>
<target name="debug" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Debug/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
<target name="debugConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
</targets>
<targets>
<target name="info" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Info/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
<target name="infoConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${callsite:className=false:methodName=false:fileName=true:includeSourcePath=false:skipFrames=2} ${message}" />
</targets>
<targets>
<target name="error" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Error/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
<target name="errorConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
</targets>
<targets>
<target name="warn" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Warning/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message}" />
<target name="warnConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message}" />
</targets>
<targets>
<target name="fatal" xsi:type="File"
openFileCacheTimeout="3600"
ConcurrentWrites="false"
fileName="${basedir}/../Logs/Log-${var:appType}-${var:appId}/Fatal/${shortdate}.log"
deleteOldFileOnStartup="false"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
<target name="fatalConsole" type="ColoredConsole"
layout="${longdate} ${var:appTypeFormat} ${var:appIdFormat} ${message} ${newline} ${stacktrace:format=Raw:topFrames=10:skipFrames=0}" />
</targets>
<rules>
<logger name="*" minlevel="Trace" writeTo="all" />
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="trace" />
<logger name="*" minlevel="Trace" maxlevel="Trace" writeTo="traceConsole" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debug" />
<logger name="*" minlevel="Debug" maxlevel="Debug" writeTo="debugConsole" />
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="info" />
<logger name="*" minlevel="Info" maxlevel="Info" writeTo="infoConsole" />
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warn" />
<logger name="*" minlevel="Warn" maxlevel="Warn" writeTo="warnConsole" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="error" />
<logger name="*" minlevel="Error" maxlevel="Error" writeTo="errorConsole" />
<logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatal" />
<logger name="*" minlevel="Fatal" maxlevel="Fatal" writeTo="fatalConsole" />
</rules>
</nlog>
ET 4.0 版本的Nlog配置可以打印log在控制台, 5.0之后可以在日志文件中查看Log, 或者更改上述配置