├── .gitignore
├── README.md
├── portproxy.service
└── src
├── PortProxy.Tests
├── PortProxy.Tests.csproj
└── StreamTransformerTest.cs
├── PortProxy.sln
└── PortProxy
├── IStreamTransformer.cs
├── IStreamValidator.cs
├── NLog.config
├── NLog.xsd
├── PortProxy.csproj
├── Program.cs
├── Properties
├── PublishProfiles
│ └── FolderProfile.pubxml
└── launchSettings.json
├── Server.cs
├── StreamTransformer.cs
└── StreamValidator.cs
/.gitignore:
--------------------------------------------------------------------------------
1 | .idea
2 | .vs
3 | obj
4 | bin
5 | *.user
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | ## PortProxy
2 |
3 | > 不能多言,言多必死,死后鞭尸。
4 |
5 | 一个简单的端口转发工具,只不过中间允许你加入自己的流验证和流变换算法。
6 |
7 | ## 运行平台
8 |
9 | 基于 .NET CORE 2.0 编写,支持Windows/Linux/Mac等平台。
10 | 分为本地端和远程端,将远程端上指定地址的端口(如远程端上的Socks5服务器端口)映射到本地。
11 | 所以请发挥自己的想象去创造用途,不能多言,言多必死,死后鞭尸。
12 |
13 | ## 开发配置
14 |
15 | - [.NET CORE 2.0](https://www.microsoft.com/net/download/windows)
16 | - [Jetbrains Rider](https://www.jetbrains.com/rider/) Or [VS2017 Community](https://www.visualstudio.com/thank-you-downloading-visual-studio/?sku=community&rel=15)
17 |
18 | ## 注意
19 |
20 | 这个代码是不完整的!`StreamValidator` 和 `StreamTransformer` 没有给出任何默认实现,请依据文档发挥自己的创意写出相关的代码。
21 |
22 | 本地生成验证数据、服务端校验认证数据、流变换双向都是要进行的操作。
23 |
24 | ## 附言
25 |
26 | 似乎用在Linux上(比如CentOS7)要比Windows上更简单诶。
27 |
28 | 比如服务端配置在远程CentOS7上:
29 |
30 | 1. 安装.net core(假定安装在`/usr/bin/dotnet`)
31 | 2. 编译后的程序发布到 `/data/server/portproxy/`
32 | 3. 将仓库中的 `portproxy.service` 文件复制到`/lib/systemd/system/`,如果路径和上述的不一致记得先改下
33 | 4. 执行 `systemctl start portproxy` 和 `systemctl enable portproxy` 启用
34 |
35 | 默认本地端口和远程端口都是`10240`,支持参数为:
36 |
37 | - **--local** 指定工作模式为本地模式,否则为远程模式
38 | - **--port=<int>** 当前监听端口,默认本地模式为`1080`,远程模式为`10240`
39 | - **--buffer=<int>** 用于流操作的缓冲区大小,单位为`KB`,默认为`128KB`
40 | - **--server=<ADDRESS>** 指定上游服务器地址,对于本地模式是指远程对应的服务器,对于远程模式则指的是转发的目标服务器
41 | - **--serverport=<int>** 指定上游服务器端口,对于本地模式默认为`10240`,对于远程模式默认为`1080`
42 |
43 | 如果需要修改默认参数,记得修改上述的service文件。
44 |
45 | 对于Windows机器,貌似可以直接用 `dotnet PortProxy.dll <参数>`直接运行,至于服务化嘛……懒得搞……完全可以搞成一个Windows Service,有兴趣的自己搞了。
46 |
47 | ## 授权
48 |
49 | > GPLv3
--------------------------------------------------------------------------------
/portproxy.service:
--------------------------------------------------------------------------------
1 | [Unit]
2 | Description=PortProxy Service
3 | After=network.target
4 |
5 | [Service]
6 | Type=simple
7 | PIDFile=/run/portproxy.pid
8 | ExecStart=/usr/bin/dotnet /data/server/portproxy/PortProxy.dll
9 | Restart=on-abort
10 | ExecReload=/bin/kill -s HUP $MAINPID
11 | ExecStop=/bin/kill -s QUIT $MAINPID
12 |
13 | [Install]
14 | WantedBy=network.target
--------------------------------------------------------------------------------
/src/PortProxy.Tests/PortProxy.Tests.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | netcoreapp2.0
4 | false
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
--------------------------------------------------------------------------------
/src/PortProxy.Tests/StreamTransformerTest.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.TestTools.UnitTesting;
2 |
3 | namespace PortProxy.Tests
4 | {
5 | using System;
6 | using System.Diagnostics;
7 | using System.Security.Cryptography;
8 |
9 | [TestClass]
10 | public class UnitTest1
11 | {
12 | [TestMethod]
13 | public void TestEncodeDecode()
14 | {
15 | var tick = new Random().Next(int.MaxValue);
16 |
17 | var s1 = new StreamTransformer();
18 | s1.Init(tick, 0);
19 | var buffer = new byte[128];
20 | var rng = new RNGCryptoServiceProvider();
21 | rng.GetBytes(buffer);
22 |
23 | var buffer1 = buffer.Clone() as byte[];
24 | s1.Encode(buffer1, 0, buffer.Length);
25 |
26 | var s2 = new StreamTransformer();
27 | s2.Init(tick, 0);
28 | s2.Decode(buffer1, 0, buffer.Length);
29 |
30 | for (int i = 0; i < buffer.Length; i++)
31 | {
32 | Debug.Assert(buffer[i] == buffer1[i], "Test failed.");
33 | }
34 | }
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/PortProxy.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio 2013
4 | VisualStudioVersion = 12.0.0.0
5 | MinimumVisualStudioVersion = 10.0.0.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortProxy", "PortProxy\PortProxy.csproj", "{0355EA10-9F6B-41DD-9E60-09D7557C82C3}"
7 | EndProject
8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PortProxy.Tests", "PortProxy.Tests\PortProxy.Tests.csproj", "{5910E57D-C82B-4B4D-81AC-9EE2AC8E3A9C}"
9 | EndProject
10 | Global
11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution
12 | Debug|Any CPU = Debug|Any CPU
13 | Release|Any CPU = Release|Any CPU
14 | EndGlobalSection
15 | GlobalSection(ProjectConfigurationPlatforms) = postSolution
16 | {0355EA10-9F6B-41DD-9E60-09D7557C82C3}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
17 | {0355EA10-9F6B-41DD-9E60-09D7557C82C3}.Debug|Any CPU.Build.0 = Debug|Any CPU
18 | {0355EA10-9F6B-41DD-9E60-09D7557C82C3}.Release|Any CPU.ActiveCfg = Release|Any CPU
19 | {0355EA10-9F6B-41DD-9E60-09D7557C82C3}.Release|Any CPU.Build.0 = Release|Any CPU
20 | {5910E57D-C82B-4B4D-81AC-9EE2AC8E3A9C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
21 | {5910E57D-C82B-4B4D-81AC-9EE2AC8E3A9C}.Debug|Any CPU.Build.0 = Debug|Any CPU
22 | {5910E57D-C82B-4B4D-81AC-9EE2AC8E3A9C}.Release|Any CPU.ActiveCfg = Release|Any CPU
23 | {5910E57D-C82B-4B4D-81AC-9EE2AC8E3A9C}.Release|Any CPU.Build.0 = Release|Any CPU
24 | EndGlobalSection
25 | GlobalSection(SolutionProperties) = preSolution
26 | HideSolutionNode = FALSE
27 | EndGlobalSection
28 | EndGlobal
29 |
--------------------------------------------------------------------------------
/src/PortProxy/IStreamTransformer.cs:
--------------------------------------------------------------------------------
1 | namespace PortProxy
2 | {
3 | ///
4 | /// 流变换类
5 | ///
6 | public interface IStreamTransformer
7 | {
8 | ///
9 | /// 对指定 里指定偏移 处的 个字节进行原位变换(混淆)
10 | ///
11 | /// 缓冲数组
12 | /// 偏移
13 | /// 长度
14 | void Encode(byte[] buffer, int offset, int length);
15 |
16 | ///
17 | /// 对指定 里指定偏移 处的 个字节进行原位变换(还原)
18 | ///
19 | /// 缓冲数组
20 | /// 偏移
21 | /// 长度
22 | void Decode(byte[] buffer, int offset, int length);
23 |
24 | ///
25 | /// 初始化
26 | ///
27 | /// 初始化的KEY,通常是服务端端口
28 | /// 初始化使用的KEY索引,允许针对一个KEY生成多个混淆方式,同一个连接的上传下载两个通道使用不同的混淆方式,可能取值为0,1
29 | void Init(int keySource, int keyIndex);
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/PortProxy/IStreamValidator.cs:
--------------------------------------------------------------------------------
1 | namespace PortProxy
2 | {
3 | using System.Net.Sockets;
4 | using System.Threading.Tasks;
5 |
6 | ///
7 | /// 流正确性认证提供类
8 | ///
9 | public interface IStreamValidator
10 | {
11 | ///
12 | /// 确认指定的流是否符合规则,仅服务端认证
13 | ///
14 | /// 来源网络流
15 | /// 认证的KEY,通常是端口
16 | /// 认证成功则返回 true
17 | Task Validate(NetworkStream stream, int key);
18 |
19 | ///
20 | /// 生成验证数据以便于提交服务端认证(仅本地)
21 | ///
22 | /// 认证的KEY,通常是端口
23 | /// 要发送给远程服务器提交认证的数据
24 | byte[] GenerateValiationData(int key);
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/PortProxy/NLog.config:
--------------------------------------------------------------------------------
1 |
2 |
3 |
9 |
10 |
13 |
14 |
15 |
19 |
20 |
21 |
26 |
27 |
32 |
33 |
36 |
39 |
43 |
44 |
45 |
46 |
47 |
48 |
49 |
53 |
54 |
55 |
56 |
57 |
--------------------------------------------------------------------------------
/src/PortProxy/NLog.xsd:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 | Watch config file for changes and reload automatically.
16 |
17 |
18 |
19 |
20 | Print internal NLog messages to the console. Default value is: false
21 |
22 |
23 |
24 |
25 | Print internal NLog messages to the console error output. Default value is: false
26 |
27 |
28 |
29 |
30 | Write internal NLog messages to the specified file.
31 |
32 |
33 |
34 |
35 | Log level threshold for internal log messages. Default value is: Info.
36 |
37 |
38 |
39 |
40 | Global log level threshold for application log messages. Messages below this level won't be logged..
41 |
42 |
43 |
44 |
45 | Throw an exception when there is an internal error. Default value is: false.
46 |
47 |
48 |
49 |
50 | Throw an exception when there is a configuration error. If not set, determined by throwExceptions.
51 |
52 |
53 |
54 |
55 | Gets or sets a value indicating whether Variables should be kept on configuration reload. Default value is: false.
56 |
57 |
58 |
59 |
60 | Write internal NLog messages to the System.Diagnostics.Trace. Default value is: false.
61 |
62 |
63 |
64 |
65 | Write timestamps for internal NLog messages. Default value is: true.
66 |
67 |
68 |
69 |
70 | Use InvariantCulture as default culture instead of CurrentCulture. Default value is: false.
71 |
72 |
73 |
74 |
75 |
76 |
77 |
78 |
79 |
80 |
81 |
82 |
83 |
84 | Make all targets within this section asynchronous (creates additional threads but the calling thread isn't blocked by any target writes).
85 |
86 |
87 |
88 |
89 |
90 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
98 |
99 |
100 |
101 | Prefix for targets/layout renderers/filters/conditions loaded from this assembly.
102 |
103 |
104 |
105 |
106 | Load NLog extensions from the specified file (*.dll)
107 |
108 |
109 |
110 |
111 | Load NLog extensions from the specified assembly. Assembly name should be fully qualified.
112 |
113 |
114 |
115 |
116 |
117 |
118 |
119 |
120 |
121 | Name of the logger. May include '*' character which acts like a wildcard. Allowed forms are: *, Name, *Name, Name* and *Name*
122 |
123 |
124 |
125 |
126 | Comma separated list of levels that this rule matches.
127 |
128 |
129 |
130 |
131 | Minimum level that this rule matches.
132 |
133 |
134 |
135 |
136 | Maximum level that this rule matches.
137 |
138 |
139 |
140 |
141 | Level that this rule matches.
142 |
143 |
144 |
145 |
146 | Comma separated list of target names.
147 |
148 |
149 |
150 |
151 | Ignore further rules if this one matches.
152 |
153 |
154 |
155 |
156 | Enable or disable logging rule. Disabled rules are ignored.
157 |
158 |
159 |
160 |
161 |
162 |
163 |
164 |
165 |
166 |
167 |
168 |
169 |
170 |
171 |
172 |
173 |
174 |
175 |
176 |
177 |
178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 |
193 |
194 |
195 |
196 |
197 |
198 | Name of the file to be included. You could use * wildcard. The name is relative to the name of the current config file.
199 |
200 |
201 |
202 |
203 | Ignore any errors in the include file.
204 |
205 |
206 |
207 |
208 |
209 |
210 | Variable name.
211 |
212 |
213 |
214 |
215 | Variable value.
216 |
217 |
218 |
219 |
220 |
221 |
222 |
223 |
224 |
225 |
226 |
227 |
228 |
229 |
230 |
231 |
232 |
233 |
234 |
235 |
236 |
237 |
238 |
239 |
240 |
241 |
242 |
243 |
244 |
245 |
246 |
247 |
248 |
249 |
250 |
251 |
252 |
253 |
254 |
255 |
256 |
257 |
258 |
259 |
260 |
261 |
262 |
263 |
264 |
265 |
266 |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 |
276 |
277 |
278 |
279 |
280 |
281 |
282 | Name of the target.
283 |
284 |
285 |
286 |
287 | Number of log events that should be processed in a batch by the lazy writer thread.
288 |
289 |
290 |
291 |
292 | Limit of full s to write before yielding into Performance is better when writing many small batches, than writing a single large batch
293 |
294 |
295 |
296 |
297 | Action to be taken when the lazy writer thread request queue count exceeds the set limit.
298 |
299 |
300 |
301 |
302 | Limit on the number of requests in the lazy writer thread request queue.
303 |
304 |
305 |
306 |
307 | Time in milliseconds to sleep between batches.
308 |
309 |
310 |
311 |
312 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
313 |
314 |
315 |
316 |
317 |
318 |
319 |
320 |
321 |
322 |
323 |
324 |
325 |
326 |
327 |
328 |
329 |
330 |
331 |
332 |
333 |
334 |
335 |
336 | Name of the target.
337 |
338 |
339 |
340 |
341 | Delay the flush until the LogEvent has been confirmed as written
342 |
343 |
344 |
345 |
346 | Condition expression. Log events who meet this condition will cause a flush on the wrapped target.
347 |
348 |
349 |
350 |
351 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
352 |
353 |
354 |
355 |
356 |
357 |
358 |
359 |
360 |
361 |
362 |
363 |
364 |
365 |
366 |
367 |
368 |
369 | Name of the target.
370 |
371 |
372 |
373 |
374 | Number of log events to be buffered.
375 |
376 |
377 |
378 |
379 | Timeout (in milliseconds) after which the contents of buffer will be flushed if there's no write in the specified period of time. Use -1 to disable timed flushes.
380 |
381 |
382 |
383 |
384 | Indicates whether to use sliding timeout.
385 |
386 |
387 |
388 |
389 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
390 |
391 |
392 |
393 |
394 |
395 |
396 |
397 |
398 |
399 |
400 |
401 |
402 |
403 |
404 |
405 |
406 |
407 |
408 |
409 |
410 |
411 |
412 |
413 |
414 |
415 |
416 |
417 |
418 |
419 |
420 |
421 |
422 |
423 |
424 |
425 | Name of the target.
426 |
427 |
428 |
429 |
430 | Encoding to be used.
431 |
432 |
433 |
434 |
435 | Instance of that is used to format log messages.
436 |
437 |
438 |
439 |
440 | End of line value if a newline is appended at the end of log message .
441 |
442 |
443 |
444 |
445 | Maximum message size in bytes.
446 |
447 |
448 |
449 |
450 | Indicates whether to append newline at the end of log message.
451 |
452 |
453 |
454 |
455 | Action that should be taken if the will be more connections than .
456 |
457 |
458 |
459 |
460 | Action that should be taken if the message is larger than maxMessageSize.
461 |
462 |
463 |
464 |
465 | Maximum current connections. 0 = no maximum.
466 |
467 |
468 |
469 |
470 | Indicates whether to keep connection open whenever possible.
471 |
472 |
473 |
474 |
475 | Size of the connection cache (number of connections which are kept alive).
476 |
477 |
478 |
479 |
480 | Network address.
481 |
482 |
483 |
484 |
485 | Maximum queue size.
486 |
487 |
488 |
489 |
490 | NDC item separator.
491 |
492 |
493 |
494 |
495 | Indicates whether to include dictionary contents.
496 |
497 |
498 |
499 |
500 | Indicates whether to include NLog-specific extensions to log4j schema.
501 |
502 |
503 |
504 |
505 | Indicates whether to include stack contents.
506 |
507 |
508 |
509 |
510 | Indicates whether to include dictionary contents.
511 |
512 |
513 |
514 |
515 | Indicates whether to include call site (class and method name) in the information sent over the network.
516 |
517 |
518 |
519 |
520 | AppInfo field. By default it's the friendly name of the current AppDomain.
521 |
522 |
523 |
524 |
525 | Indicates whether to include source info (file name and line number) in the information sent over the network.
526 |
527 |
528 |
529 |
530 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
531 |
532 |
533 |
534 |
535 |
536 |
537 |
538 |
539 |
540 |
541 |
542 |
543 |
544 |
545 |
546 |
547 |
548 |
549 |
550 |
551 |
552 |
553 |
554 |
555 |
556 |
557 | Layout that should be use to calcuate the value for the parameter.
558 |
559 |
560 |
561 |
562 | Viewer parameter name.
563 |
564 |
565 |
566 |
567 |
568 |
569 |
570 |
571 |
572 |
573 |
574 |
575 |
576 |
577 |
578 |
579 |
580 |
581 |
582 |
583 |
584 | Name of the target.
585 |
586 |
587 |
588 |
589 | Text to be rendered.
590 |
591 |
592 |
593 |
594 | Header.
595 |
596 |
597 |
598 |
599 | Footer.
600 |
601 |
602 |
603 |
604 | Indicates whether to use default row highlighting rules.
605 |
606 |
607 |
608 |
609 | Indicates whether to auto-check if the console is available. - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App)
610 |
611 |
612 |
613 |
614 | The encoding for writing messages to the .
615 |
616 |
617 |
618 |
619 | Indicates whether the error stream (stderr) should be used instead of the output stream (stdout).
620 |
621 |
622 |
623 |
624 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
625 |
626 |
627 |
628 |
629 |
630 |
631 |
632 |
633 |
634 |
635 |
636 |
637 |
638 |
639 |
640 |
641 |
642 |
643 |
644 |
645 |
646 |
647 |
648 |
649 |
650 |
651 |
652 |
653 |
654 |
655 |
656 |
657 |
658 |
659 | Condition that must be met in order to set the specified foreground and background color.
660 |
661 |
662 |
663 |
664 | Background color.
665 |
666 |
667 |
668 |
669 | Foreground color.
670 |
671 |
672 |
673 |
674 |
675 |
676 |
677 |
678 |
679 |
680 |
681 |
682 |
683 |
684 |
685 | Indicates whether to ignore case when comparing texts.
686 |
687 |
688 |
689 |
690 | Regular expression to be matched. You must specify either text or regex.
691 |
692 |
693 |
694 |
695 | Text to be matched. You must specify either text or regex.
696 |
697 |
698 |
699 |
700 | Indicates whether to match whole words only.
701 |
702 |
703 |
704 |
705 | Compile the ? This can improve the performance, but at the costs of more memory usage. If false, the Regex Cache is used.
706 |
707 |
708 |
709 |
710 | Background color.
711 |
712 |
713 |
714 |
715 | Foreground color.
716 |
717 |
718 |
719 |
720 |
721 |
722 |
723 |
724 |
725 |
726 |
727 |
728 |
729 |
730 |
731 |
732 |
733 |
734 | Name of the target.
735 |
736 |
737 |
738 |
739 | Text to be rendered.
740 |
741 |
742 |
743 |
744 | Header.
745 |
746 |
747 |
748 |
749 | Footer.
750 |
751 |
752 |
753 |
754 | Indicates whether to send the log messages to the standard error instead of the standard output.
755 |
756 |
757 |
758 |
759 | Indicates whether to auto-check if the console is available - Disables console writing if Environment.UserInteractive = False (Windows Service) - Disables console writing if Console Standard Input is not available (Non-Console-App)
760 |
761 |
762 |
763 |
764 | The encoding for writing messages to the .
765 |
766 |
767 |
768 |
769 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
770 |
771 |
772 |
773 |
774 |
775 |
776 |
777 |
778 |
779 |
780 |
781 |
782 |
783 |
784 |
785 |
786 |
787 |
788 |
789 |
790 |
791 |
792 |
793 |
794 |
795 |
796 |
797 |
798 |
799 | Name of the target.
800 |
801 |
802 |
803 |
804 | Obsolete - value will be ignored! The logging code always runs outside of transaction. Gets or sets a value indicating whether to use database transactions. Some data providers require this.
805 |
806 |
807 |
808 |
809 | Database user name. If the ConnectionString is not provided this value will be used to construct the "User ID=" part of the connection string.
810 |
811 |
812 |
813 |
814 | Name of the database provider.
815 |
816 |
817 |
818 |
819 | Database password. If the ConnectionString is not provided this value will be used to construct the "Password=" part of the connection string.
820 |
821 |
822 |
823 |
824 | Indicates whether to keep the database connection open between the log events.
825 |
826 |
827 |
828 |
829 | Database name. If the ConnectionString is not provided this value will be used to construct the "Database=" part of the connection string.
830 |
831 |
832 |
833 |
834 | Name of the connection string (as specified in <connectionStrings> configuration section.
835 |
836 |
837 |
838 |
839 | Connection string. When provided, it overrides the values specified in DBHost, DBUserName, DBPassword, DBDatabase.
840 |
841 |
842 |
843 |
844 | Database host name. If the ConnectionString is not provided this value will be used to construct the "Server=" part of the connection string.
845 |
846 |
847 |
848 |
849 | Connection string using for installation and uninstallation. If not provided, regular ConnectionString is being used.
850 |
851 |
852 |
853 |
854 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
855 |
856 |
857 |
858 |
859 | Text of the SQL command to be run on each log level.
860 |
861 |
862 |
863 |
864 | Type of the SQL command to be run on each log level.
865 |
866 |
867 |
868 |
869 |
870 |
871 |
872 |
873 |
874 |
875 |
876 |
877 |
878 |
879 |
880 |
881 |
882 |
883 |
884 |
885 |
886 |
887 | Type of the command.
888 |
889 |
890 |
891 |
892 | Connection string to run the command against. If not provided, connection string from the target is used.
893 |
894 |
895 |
896 |
897 | Indicates whether to ignore failures.
898 |
899 |
900 |
901 |
902 | Command text.
903 |
904 |
905 |
906 |
907 |
908 |
909 |
910 |
911 |
912 |
913 |
914 |
915 |
916 | Layout that should be use to calcuate the value for the parameter.
917 |
918 |
919 |
920 |
921 | Database parameter name.
922 |
923 |
924 |
925 |
926 | Database parameter precision.
927 |
928 |
929 |
930 |
931 | Database parameter scale.
932 |
933 |
934 |
935 |
936 | Database parameter size.
937 |
938 |
939 |
940 |
941 |
942 |
943 |
944 |
945 |
946 |
947 |
948 |
949 |
950 |
951 |
952 | Name of the target.
953 |
954 |
955 |
956 |
957 | Text to be rendered.
958 |
959 |
960 |
961 |
962 | Header.
963 |
964 |
965 |
966 |
967 | Footer.
968 |
969 |
970 |
971 |
972 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
973 |
974 |
975 |
976 |
977 |
978 |
979 |
980 |
981 |
982 |
983 |
984 |
985 |
986 |
987 |
988 | Name of the target.
989 |
990 |
991 |
992 |
993 | Layout used to format log messages.
994 |
995 |
996 |
997 |
998 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
999 |
1000 |
1001 |
1002 |
1003 |
1004 |
1005 |
1006 |
1007 |
1008 |
1009 |
1010 |
1011 |
1012 |
1013 |
1014 |
1015 |
1016 |
1017 |
1018 |
1019 |
1020 |
1021 |
1022 |
1023 | Name of the target.
1024 |
1025 |
1026 |
1027 |
1028 | Layout used to format log messages.
1029 |
1030 |
1031 |
1032 |
1033 | Layout that renders event Category.
1034 |
1035 |
1036 |
1037 |
1038 | Layout that renders event ID.
1039 |
1040 |
1041 |
1042 |
1043 | Name of the Event Log to write to. This can be System, Application or any user-defined name.
1044 |
1045 |
1046 |
1047 |
1048 | Name of the machine on which Event Log service is running.
1049 |
1050 |
1051 |
1052 |
1053 | Value to be used as the event Source.
1054 |
1055 |
1056 |
1057 |
1058 | Action to take if the message is larger than the option.
1059 |
1060 |
1061 |
1062 |
1063 | Optional entrytype. When not set, or when not convertable to then determined by
1064 |
1065 |
1066 |
1067 |
1068 | Maximum Event log size in kilobytes. If null, the value won't be set. Default is 512 Kilobytes as specified by Eventlog API
1069 |
1070 |
1071 |
1072 |
1073 | Message length limit to write to the Event Log.
1074 |
1075 |
1076 |
1077 |
1078 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1079 |
1080 |
1081 |
1082 |
1083 |
1084 |
1085 |
1086 |
1087 |
1088 |
1089 |
1090 |
1091 |
1092 |
1093 |
1094 |
1095 |
1096 |
1097 |
1098 |
1099 |
1100 |
1101 | Name of the target.
1102 |
1103 |
1104 |
1105 |
1106 | Indicates whether to return to the first target after any successful write.
1107 |
1108 |
1109 |
1110 |
1111 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1112 |
1113 |
1114 |
1115 |
1116 |
1117 |
1118 |
1119 |
1120 |
1121 |
1122 |
1123 |
1124 |
1125 |
1126 |
1127 |
1128 |
1129 |
1130 |
1131 |
1132 |
1133 |
1134 |
1135 |
1136 |
1137 |
1138 |
1139 |
1140 |
1141 |
1142 |
1143 |
1144 |
1145 |
1146 |
1147 |
1148 |
1149 |
1150 |
1151 |
1152 |
1153 |
1154 |
1155 |
1156 |
1157 |
1158 |
1159 |
1160 |
1161 |
1162 | Name of the target.
1163 |
1164 |
1165 |
1166 |
1167 | Text to be rendered.
1168 |
1169 |
1170 |
1171 |
1172 | Header.
1173 |
1174 |
1175 |
1176 |
1177 | Footer.
1178 |
1179 |
1180 |
1181 |
1182 | File encoding.
1183 |
1184 |
1185 |
1186 |
1187 | Line ending mode.
1188 |
1189 |
1190 |
1191 |
1192 | Way file archives are numbered.
1193 |
1194 |
1195 |
1196 |
1197 | Name of the file to be used for an archive.
1198 |
1199 |
1200 |
1201 |
1202 | Indicates whether to automatically archive log files every time the specified time passes.
1203 |
1204 |
1205 |
1206 |
1207 | Size in bytes above which log files will be automatically archived. Warning: combining this with isn't supported. We cannot create multiple archive files, if they should have the same name. Choose:
1208 |
1209 |
1210 |
1211 |
1212 | Indicates whether to compress archive files into the zip archive format.
1213 |
1214 |
1215 |
1216 |
1217 | Maximum number of archive files that should be kept.
1218 |
1219 |
1220 |
1221 |
1222 | Gets or set a value indicating whether a managed file stream is forced, instead of using the native implementation.
1223 |
1224 |
1225 |
1226 |
1227 | Is the an absolute or relative path?
1228 |
1229 |
1230 |
1231 |
1232 | Cleanup invalid values in a filename, e.g. slashes in a filename. If set to true, this can impact the performance of massive writes. If set to false, nothing gets written when the filename is wrong.
1233 |
1234 |
1235 |
1236 |
1237 | Whether or not this target should just discard all data that its asked to write. Mostly used for when testing NLog Stack except final write
1238 |
1239 |
1240 |
1241 |
1242 | Is the an absolute or relative path?
1243 |
1244 |
1245 |
1246 |
1247 | Value indicationg whether file creation calls should be synchronized by a system global mutex.
1248 |
1249 |
1250 |
1251 |
1252 | Maximum number of log filenames that should be stored as existing.
1253 |
1254 |
1255 |
1256 |
1257 | Indicates whether the footer should be written only when the file is archived.
1258 |
1259 |
1260 |
1261 |
1262 | Name of the file to write to.
1263 |
1264 |
1265 |
1266 |
1267 | Value specifying the date format to use when archiving files.
1268 |
1269 |
1270 |
1271 |
1272 | Indicates whether to archive old log file on startup.
1273 |
1274 |
1275 |
1276 |
1277 | Indicates whether to create directories if they do not exist.
1278 |
1279 |
1280 |
1281 |
1282 | File attributes (Windows only).
1283 |
1284 |
1285 |
1286 |
1287 | Indicates whether to delete old log file on startup.
1288 |
1289 |
1290 |
1291 |
1292 | Indicates whether to replace file contents on each write instead of appending log message at the end.
1293 |
1294 |
1295 |
1296 |
1297 | Indicates whether to enable log file(s) to be deleted.
1298 |
1299 |
1300 |
1301 |
1302 | Number of times the write is appended on the file before NLog discards the log message.
1303 |
1304 |
1305 |
1306 |
1307 | Indicates whether concurrent writes to the log file by multiple processes on the same host.
1308 |
1309 |
1310 |
1311 |
1312 | Indicates whether to keep log file open instead of opening and closing it on each logging event.
1313 |
1314 |
1315 |
1316 |
1317 | Indicates whether concurrent writes to the log file by multiple processes on different network hosts.
1318 |
1319 |
1320 |
1321 |
1322 | Number of files to be kept open. Setting this to a higher value may improve performance in a situation where a single File target is writing to many files (such as splitting by level or by logger).
1323 |
1324 |
1325 |
1326 |
1327 | Maximum number of seconds that files are kept open. If this number is negative the files are not automatically closed after a period of inactivity.
1328 |
1329 |
1330 |
1331 |
1332 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1333 |
1334 |
1335 |
1336 |
1337 | Log file buffer size in bytes.
1338 |
1339 |
1340 |
1341 |
1342 | Indicates whether to automatically flush the file buffers after each log message.
1343 |
1344 |
1345 |
1346 |
1347 | Delay in milliseconds to wait before attempting to write to the file again.
1348 |
1349 |
1350 |
1351 |
1352 |
1353 |
1354 |
1355 |
1356 |
1357 |
1358 |
1359 |
1360 |
1361 |
1362 |
1363 |
1364 |
1365 |
1366 |
1367 |
1368 |
1369 |
1370 |
1371 |
1372 |
1373 |
1374 |
1375 |
1376 |
1377 |
1378 |
1379 |
1380 |
1381 |
1382 |
1383 |
1384 |
1385 |
1386 |
1387 |
1388 |
1389 |
1390 |
1391 |
1392 |
1393 |
1394 |
1395 |
1396 |
1397 |
1398 |
1399 |
1400 |
1401 |
1402 |
1403 |
1404 |
1405 |
1406 |
1407 |
1408 |
1409 |
1410 |
1411 |
1412 |
1413 |
1414 |
1415 | Name of the target.
1416 |
1417 |
1418 |
1419 |
1420 | Condition expression. Log events who meet this condition will be forwarded to the wrapped target.
1421 |
1422 |
1423 |
1424 |
1425 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1426 |
1427 |
1428 |
1429 |
1430 |
1431 |
1432 |
1433 |
1434 |
1435 |
1436 |
1437 |
1438 |
1439 |
1440 |
1441 |
1442 |
1443 |
1444 |
1445 |
1446 |
1447 | Name of the target.
1448 |
1449 |
1450 |
1451 |
1452 | Windows domain name to change context to.
1453 |
1454 |
1455 |
1456 |
1457 | Required impersonation level.
1458 |
1459 |
1460 |
1461 |
1462 | Type of the logon provider.
1463 |
1464 |
1465 |
1466 |
1467 | Logon Type.
1468 |
1469 |
1470 |
1471 |
1472 | User account password.
1473 |
1474 |
1475 |
1476 |
1477 | Indicates whether to revert to the credentials of the process instead of impersonating another user.
1478 |
1479 |
1480 |
1481 |
1482 | Username to change context to.
1483 |
1484 |
1485 |
1486 |
1487 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1488 |
1489 |
1490 |
1491 |
1492 |
1493 |
1494 |
1495 |
1496 |
1497 |
1498 |
1499 |
1500 |
1501 |
1502 |
1503 |
1504 |
1505 |
1506 |
1507 |
1508 |
1509 |
1510 |
1511 |
1512 |
1513 |
1514 |
1515 |
1516 |
1517 |
1518 |
1519 |
1520 |
1521 |
1522 |
1523 |
1524 |
1525 |
1526 |
1527 | Name of the target.
1528 |
1529 |
1530 |
1531 |
1532 | Interval in which messages will be written up to the number of messages.
1533 |
1534 |
1535 |
1536 |
1537 | Maximum allowed number of messages written per .
1538 |
1539 |
1540 |
1541 |
1542 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1543 |
1544 |
1545 |
1546 |
1547 |
1548 |
1549 |
1550 |
1551 |
1552 |
1553 |
1554 |
1555 |
1556 |
1557 |
1558 |
1559 |
1560 |
1561 |
1562 |
1563 |
1564 | Name of the target.
1565 |
1566 |
1567 |
1568 |
1569 | Endpoint address.
1570 |
1571 |
1572 |
1573 |
1574 | Name of the endpoint configuration in WCF configuration file.
1575 |
1576 |
1577 |
1578 |
1579 | Indicates whether to use a WCF service contract that is one way (fire and forget) or two way (request-reply)
1580 |
1581 |
1582 |
1583 |
1584 | Client ID.
1585 |
1586 |
1587 |
1588 |
1589 | Indicates whether to include per-event properties in the payload sent to the server.
1590 |
1591 |
1592 |
1593 |
1594 | Indicates whether to use binary message encoding.
1595 |
1596 |
1597 |
1598 |
1599 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1600 |
1601 |
1602 |
1603 |
1604 |
1605 |
1606 |
1607 |
1608 |
1609 |
1610 |
1611 |
1612 |
1613 |
1614 |
1615 | Layout that should be use to calculate the value for the parameter.
1616 |
1617 |
1618 |
1619 |
1620 | Name of the parameter.
1621 |
1622 |
1623 |
1624 |
1625 | Type of the parameter.
1626 |
1627 |
1628 |
1629 |
1630 | Type of the parameter. Obsolete alias for
1631 |
1632 |
1633 |
1634 |
1635 | Parameter can combine multiple LogEvents into a single parameter value
1636 |
1637 |
1638 |
1639 |
1640 |
1641 |
1642 |
1643 |
1644 |
1645 |
1646 |
1647 |
1648 |
1649 |
1650 |
1651 |
1652 |
1653 |
1654 |
1655 |
1656 |
1657 |
1658 |
1659 |
1660 |
1661 |
1662 |
1663 |
1664 |
1665 |
1666 |
1667 |
1668 |
1669 |
1670 |
1671 |
1672 | Name of the target.
1673 |
1674 |
1675 |
1676 |
1677 | Text to be rendered.
1678 |
1679 |
1680 |
1681 |
1682 | Header.
1683 |
1684 |
1685 |
1686 |
1687 | Footer.
1688 |
1689 |
1690 |
1691 |
1692 | Indicates whether to send message as HTML instead of plain text.
1693 |
1694 |
1695 |
1696 |
1697 | Encoding to be used for sending e-mail.
1698 |
1699 |
1700 |
1701 |
1702 | Indicates whether to add new lines between log entries.
1703 |
1704 |
1705 |
1706 |
1707 | CC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com).
1708 |
1709 |
1710 |
1711 |
1712 | Recipients' email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com).
1713 |
1714 |
1715 |
1716 |
1717 | BCC email addresses separated by semicolons (e.g. john@domain.com;jane@domain.com).
1718 |
1719 |
1720 |
1721 |
1722 | Mail message body (repeated for each log message send in one mail).
1723 |
1724 |
1725 |
1726 |
1727 | Mail subject.
1728 |
1729 |
1730 |
1731 |
1732 | Sender's email address (e.g. joe@domain.com).
1733 |
1734 |
1735 |
1736 |
1737 | Indicates the SMTP client timeout.
1738 |
1739 |
1740 |
1741 |
1742 | Priority used for sending mails.
1743 |
1744 |
1745 |
1746 |
1747 | Indicates whether NewLine characters in the body should be replaced with tags.
1748 |
1749 |
1750 |
1751 |
1752 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1753 |
1754 |
1755 |
1756 |
1757 | SMTP Server to be used for sending.
1758 |
1759 |
1760 |
1761 |
1762 | SMTP Authentication mode.
1763 |
1764 |
1765 |
1766 |
1767 | Username used to connect to SMTP server (used when SmtpAuthentication is set to "basic").
1768 |
1769 |
1770 |
1771 |
1772 | Password used to authenticate against SMTP server (used when SmtpAuthentication is set to "basic").
1773 |
1774 |
1775 |
1776 |
1777 | Indicates whether SSL (secure sockets layer) should be used when communicating with SMTP server.
1778 |
1779 |
1780 |
1781 |
1782 | Port number that SMTP Server is listening on.
1783 |
1784 |
1785 |
1786 |
1787 | Indicates whether the default Settings from System.Net.MailSettings should be used.
1788 |
1789 |
1790 |
1791 |
1792 | Folder where applications save mail messages to be processed by the local SMTP server.
1793 |
1794 |
1795 |
1796 |
1797 | Specifies how outgoing email messages will be handled.
1798 |
1799 |
1800 |
1801 |
1802 |
1803 |
1804 |
1805 |
1806 |
1807 |
1808 |
1809 |
1810 |
1811 |
1812 |
1813 |
1814 |
1815 |
1816 |
1817 |
1818 |
1819 |
1820 |
1821 |
1822 |
1823 |
1824 |
1825 |
1826 |
1827 | Name of the target.
1828 |
1829 |
1830 |
1831 |
1832 | Layout used to format log messages.
1833 |
1834 |
1835 |
1836 |
1837 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1838 |
1839 |
1840 |
1841 |
1842 |
1843 |
1844 |
1845 |
1846 |
1847 |
1848 |
1849 |
1850 |
1851 |
1852 |
1853 |
1854 |
1855 | Name of the target.
1856 |
1857 |
1858 |
1859 |
1860 | Class name.
1861 |
1862 |
1863 |
1864 |
1865 | Method name. The method must be public and static. Use the AssemblyQualifiedName , https://msdn.microsoft.com/en-us/library/system.type.assemblyqualifiedname(v=vs.110).aspx e.g.
1866 |
1867 |
1868 |
1869 |
1870 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1871 |
1872 |
1873 |
1874 |
1875 |
1876 |
1877 |
1878 |
1879 |
1880 |
1881 |
1882 |
1883 |
1884 |
1885 |
1886 |
1887 |
1888 |
1889 |
1890 |
1891 |
1892 |
1893 |
1894 |
1895 |
1896 |
1897 | Name of the target.
1898 |
1899 |
1900 |
1901 |
1902 | Layout used to format log messages.
1903 |
1904 |
1905 |
1906 |
1907 | Encoding to be used.
1908 |
1909 |
1910 |
1911 |
1912 | End of line value if a newline is appended at the end of log message .
1913 |
1914 |
1915 |
1916 |
1917 | Maximum message size in bytes.
1918 |
1919 |
1920 |
1921 |
1922 | Indicates whether to append newline at the end of log message.
1923 |
1924 |
1925 |
1926 |
1927 | Action that should be taken if the will be more connections than .
1928 |
1929 |
1930 |
1931 |
1932 | Action that should be taken if the message is larger than maxMessageSize.
1933 |
1934 |
1935 |
1936 |
1937 | Network address.
1938 |
1939 |
1940 |
1941 |
1942 | Size of the connection cache (number of connections which are kept alive).
1943 |
1944 |
1945 |
1946 |
1947 | Indicates whether to keep connection open whenever possible.
1948 |
1949 |
1950 |
1951 |
1952 | Maximum current connections. 0 = no maximum.
1953 |
1954 |
1955 |
1956 |
1957 | Maximum queue size.
1958 |
1959 |
1960 |
1961 |
1962 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
1963 |
1964 |
1965 |
1966 |
1967 |
1968 |
1969 |
1970 |
1971 |
1972 |
1973 |
1974 |
1975 |
1976 |
1977 |
1978 |
1979 |
1980 |
1981 |
1982 |
1983 |
1984 |
1985 |
1986 |
1987 |
1988 |
1989 |
1990 |
1991 |
1992 |
1993 |
1994 |
1995 |
1996 |
1997 |
1998 | Name of the target.
1999 |
2000 |
2001 |
2002 |
2003 | Encoding to be used.
2004 |
2005 |
2006 |
2007 |
2008 | Instance of that is used to format log messages.
2009 |
2010 |
2011 |
2012 |
2013 | End of line value if a newline is appended at the end of log message .
2014 |
2015 |
2016 |
2017 |
2018 | Maximum message size in bytes.
2019 |
2020 |
2021 |
2022 |
2023 | Indicates whether to append newline at the end of log message.
2024 |
2025 |
2026 |
2027 |
2028 | Action that should be taken if the will be more connections than .
2029 |
2030 |
2031 |
2032 |
2033 | Action that should be taken if the message is larger than maxMessageSize.
2034 |
2035 |
2036 |
2037 |
2038 | Maximum current connections. 0 = no maximum.
2039 |
2040 |
2041 |
2042 |
2043 | Indicates whether to keep connection open whenever possible.
2044 |
2045 |
2046 |
2047 |
2048 | Size of the connection cache (number of connections which are kept alive).
2049 |
2050 |
2051 |
2052 |
2053 | Network address.
2054 |
2055 |
2056 |
2057 |
2058 | Maximum queue size.
2059 |
2060 |
2061 |
2062 |
2063 | NDC item separator.
2064 |
2065 |
2066 |
2067 |
2068 | Indicates whether to include dictionary contents.
2069 |
2070 |
2071 |
2072 |
2073 | Indicates whether to include NLog-specific extensions to log4j schema.
2074 |
2075 |
2076 |
2077 |
2078 | Indicates whether to include stack contents.
2079 |
2080 |
2081 |
2082 |
2083 | Indicates whether to include dictionary contents.
2084 |
2085 |
2086 |
2087 |
2088 | Indicates whether to include call site (class and method name) in the information sent over the network.
2089 |
2090 |
2091 |
2092 |
2093 | AppInfo field. By default it's the friendly name of the current AppDomain.
2094 |
2095 |
2096 |
2097 |
2098 | Indicates whether to include source info (file name and line number) in the information sent over the network.
2099 |
2100 |
2101 |
2102 |
2103 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2104 |
2105 |
2106 |
2107 |
2108 |
2109 |
2110 |
2111 |
2112 |
2113 |
2114 |
2115 |
2116 |
2117 |
2118 |
2119 |
2120 | Name of the target.
2121 |
2122 |
2123 |
2124 |
2125 | Layout used to format log messages.
2126 |
2127 |
2128 |
2129 |
2130 | Indicates whether to perform layout calculation.
2131 |
2132 |
2133 |
2134 |
2135 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2136 |
2137 |
2138 |
2139 |
2140 |
2141 |
2142 |
2143 |
2144 |
2145 |
2146 |
2147 |
2148 |
2149 |
2150 |
2151 | Name of the target.
2152 |
2153 |
2154 |
2155 |
2156 | Layout used to format log messages.
2157 |
2158 |
2159 |
2160 |
2161 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2162 |
2163 |
2164 |
2165 |
2166 |
2167 |
2168 |
2169 |
2170 |
2171 |
2172 |
2173 |
2174 |
2175 |
2176 |
2177 |
2178 |
2179 |
2180 |
2181 |
2182 |
2183 | Name of the target.
2184 |
2185 |
2186 |
2187 |
2188 | Indicates whether performance counter should be automatically created.
2189 |
2190 |
2191 |
2192 |
2193 | Name of the performance counter category.
2194 |
2195 |
2196 |
2197 |
2198 | Counter help text.
2199 |
2200 |
2201 |
2202 |
2203 | Name of the performance counter.
2204 |
2205 |
2206 |
2207 |
2208 | Performance counter type.
2209 |
2210 |
2211 |
2212 |
2213 | The value by which to increment the counter.
2214 |
2215 |
2216 |
2217 |
2218 | Performance counter instance name.
2219 |
2220 |
2221 |
2222 |
2223 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2224 |
2225 |
2226 |
2227 |
2228 |
2229 |
2230 |
2231 |
2232 |
2233 |
2234 |
2235 |
2236 |
2237 |
2238 |
2239 |
2240 |
2241 |
2242 |
2243 |
2244 |
2245 |
2246 |
2247 |
2248 |
2249 |
2250 |
2251 |
2252 |
2253 |
2254 |
2255 |
2256 |
2257 |
2258 |
2259 |
2260 |
2261 |
2262 |
2263 |
2264 |
2265 |
2266 |
2267 |
2268 |
2269 |
2270 |
2271 |
2272 | Name of the target.
2273 |
2274 |
2275 |
2276 |
2277 | Default filter to be applied when no specific rule matches.
2278 |
2279 |
2280 |
2281 |
2282 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2283 |
2284 |
2285 |
2286 |
2287 |
2288 |
2289 |
2290 |
2291 |
2292 |
2293 |
2294 |
2295 | Condition to be tested.
2296 |
2297 |
2298 |
2299 |
2300 | Resulting filter to be applied when the condition matches.
2301 |
2302 |
2303 |
2304 |
2305 |
2306 |
2307 |
2308 |
2309 |
2310 |
2311 |
2312 |
2313 | Name of the target.
2314 |
2315 |
2316 |
2317 |
2318 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2319 |
2320 |
2321 |
2322 |
2323 |
2324 |
2325 |
2326 |
2327 |
2328 |
2329 |
2330 |
2331 |
2332 |
2333 |
2334 | Name of the target.
2335 |
2336 |
2337 |
2338 |
2339 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2340 |
2341 |
2342 |
2343 |
2344 | Number of times to repeat each log message.
2345 |
2346 |
2347 |
2348 |
2349 |
2350 |
2351 |
2352 |
2353 |
2354 |
2355 |
2356 |
2357 |
2358 |
2359 |
2360 |
2361 | Name of the target.
2362 |
2363 |
2364 |
2365 |
2366 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2367 |
2368 |
2369 |
2370 |
2371 | Number of retries that should be attempted on the wrapped target in case of a failure.
2372 |
2373 |
2374 |
2375 |
2376 | Time to wait between retries in milliseconds.
2377 |
2378 |
2379 |
2380 |
2381 |
2382 |
2383 |
2384 |
2385 |
2386 |
2387 |
2388 |
2389 |
2390 |
2391 | Name of the target.
2392 |
2393 |
2394 |
2395 |
2396 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2397 |
2398 |
2399 |
2400 |
2401 |
2402 |
2403 |
2404 |
2405 |
2406 |
2407 |
2408 |
2409 |
2410 |
2411 | Name of the target.
2412 |
2413 |
2414 |
2415 |
2416 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2417 |
2418 |
2419 |
2420 |
2421 |
2422 |
2423 |
2424 |
2425 |
2426 |
2427 |
2428 |
2429 |
2430 |
2431 |
2432 | Name of the target.
2433 |
2434 |
2435 |
2436 |
2437 | Layout used to format log messages.
2438 |
2439 |
2440 |
2441 |
2442 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2443 |
2444 |
2445 |
2446 |
2447 |
2448 |
2449 |
2450 |
2451 |
2452 |
2453 |
2454 |
2455 |
2456 |
2457 |
2458 |
2459 |
2460 |
2461 |
2462 |
2463 |
2464 |
2465 |
2466 |
2467 |
2468 |
2469 |
2470 | Name of the target.
2471 |
2472 |
2473 |
2474 |
2475 | Should we include the BOM (Byte-order-mark) for UTF? Influences the property. This will only work for UTF-8.
2476 |
2477 |
2478 |
2479 |
2480 | Target supports reuse of internal buffers, and doesn't have to constantly allocate new buffers Required for legacy NLog-targets, that expects buffers to remain stable after Write-method exit
2481 |
2482 |
2483 |
2484 |
2485 | Encoding.
2486 |
2487 |
2488 |
2489 |
2490 | Value whether escaping be done according to the old NLog style (Very non-standard)
2491 |
2492 |
2493 |
2494 |
2495 | Value whether escaping be done according to Rfc3986 (Supports Internationalized Resource Identifiers - IRIs)
2496 |
2497 |
2498 |
2499 |
2500 | Web service method name. Only used with Soap.
2501 |
2502 |
2503 |
2504 |
2505 | Web service namespace. Only used with Soap.
2506 |
2507 |
2508 |
2509 |
2510 | Indicates whether to pre-authenticate the HttpWebRequest (Requires 'Authorization' in parameters)
2511 |
2512 |
2513 |
2514 |
2515 | Protocol to be used when calling web service.
2516 |
2517 |
2518 |
2519 |
2520 | Web service URL.
2521 |
2522 |
2523 |
2524 |
2525 | Name of the root XML element, if POST of XML document chosen. If so, this property must not be null. (see and ).
2526 |
2527 |
2528 |
2529 |
2530 | (optional) root namespace of the XML document, if POST of XML document chosen. (see and ).
2531 |
2532 |
2533 |
2534 |
2535 |
2536 |
2537 |
2538 |
2539 |
2540 |
2541 |
2542 |
2543 |
2544 |
2545 |
2546 |
2547 |
2548 |
2549 |
2550 |
2551 |
2552 |
2553 |
2554 |
2555 |
2556 |
2557 |
2558 |
2559 |
2560 |
2561 |
2562 |
2563 |
2564 |
2565 |
2566 |
2567 |
2568 |
2569 |
2570 |
2571 |
2572 |
2573 |
2574 | Footer layout.
2575 |
2576 |
2577 |
2578 |
2579 | Header layout.
2580 |
2581 |
2582 |
2583 |
2584 | Body layout (can be repeated multiple times).
2585 |
2586 |
2587 |
2588 |
2589 | Custom column delimiter value (valid when ColumnDelimiter is set to 'Custom').
2590 |
2591 |
2592 |
2593 |
2594 | Column delimiter.
2595 |
2596 |
2597 |
2598 |
2599 | Quote Character.
2600 |
2601 |
2602 |
2603 |
2604 | Quoting mode.
2605 |
2606 |
2607 |
2608 |
2609 | Indicates whether CVS should include header.
2610 |
2611 |
2612 |
2613 |
2614 |
2615 |
2616 |
2617 |
2618 |
2619 |
2620 |
2621 |
2622 |
2623 |
2624 |
2625 |
2626 |
2627 |
2628 |
2629 |
2630 |
2631 |
2632 |
2633 |
2634 |
2635 |
2636 |
2637 |
2638 |
2639 |
2640 | Layout of the column.
2641 |
2642 |
2643 |
2644 |
2645 | Name of the column.
2646 |
2647 |
2648 |
2649 |
2650 |
2651 |
2652 |
2653 |
2654 |
2655 |
2656 |
2657 |
2658 |
2659 |
2660 |
2661 |
2662 |
2663 | List of property names to exclude when is true
2664 |
2665 |
2666 |
2667 |
2668 | Option to include all properties from the log events
2669 |
2670 |
2671 |
2672 |
2673 | Indicates whether to include contents of the dictionary.
2674 |
2675 |
2676 |
2677 |
2678 | Indicates whether to include contents of the dictionary.
2679 |
2680 |
2681 |
2682 |
2683 | Option to render the empty object value {}
2684 |
2685 |
2686 |
2687 |
2688 | Option to suppress the extra spaces in the output json
2689 |
2690 |
2691 |
2692 |
2693 |
2694 |
2695 |
2696 |
2697 |
2698 |
2699 |
2700 |
2701 |
2702 |
2703 | Determines wether or not this attribute will be Json encoded.
2704 |
2705 |
2706 |
2707 |
2708 | Indicates whether to escape non-ascii characters
2709 |
2710 |
2711 |
2712 |
2713 | Layout that will be rendered as the attribute's value.
2714 |
2715 |
2716 |
2717 |
2718 | Name of the attribute.
2719 |
2720 |
2721 |
2722 |
2723 |
2724 |
2725 |
2726 |
2727 |
2728 |
2729 |
2730 |
2731 |
2732 | Footer layout.
2733 |
2734 |
2735 |
2736 |
2737 | Header layout.
2738 |
2739 |
2740 |
2741 |
2742 | Body layout (can be repeated multiple times).
2743 |
2744 |
2745 |
2746 |
2747 |
2748 |
2749 |
2750 |
2751 |
2752 |
2753 |
2754 |
2755 |
2756 |
2757 |
2758 | Option to include all properties from the log events
2759 |
2760 |
2761 |
2762 |
2763 | Indicates whether to include contents of the dictionary.
2764 |
2765 |
2766 |
2767 |
2768 | Indicates whether to include contents of the dictionary.
2769 |
2770 |
2771 |
2772 |
2773 |
2774 |
2775 |
2776 |
2777 |
2778 |
2779 |
2780 |
2781 |
2782 | Layout text.
2783 |
2784 |
2785 |
2786 |
2787 |
2788 |
2789 |
2790 |
2791 |
2792 |
2793 |
2794 |
2795 |
2796 |
2797 | Action to be taken when filter matches.
2798 |
2799 |
2800 |
2801 |
2802 | Condition expression.
2803 |
2804 |
2805 |
2806 |
2807 |
2808 |
2809 |
2810 |
2811 |
2812 |
2813 |
2814 |
2815 |
2816 |
2817 |
2818 |
2819 |
2820 |
2821 |
2822 |
2823 |
2824 |
2825 |
2826 |
2827 |
2828 | Action to be taken when filter matches.
2829 |
2830 |
2831 |
2832 |
2833 | Indicates whether to ignore case when comparing strings.
2834 |
2835 |
2836 |
2837 |
2838 | Layout to be used to filter log messages.
2839 |
2840 |
2841 |
2842 |
2843 | Substring to be matched.
2844 |
2845 |
2846 |
2847 |
2848 |
2849 |
2850 |
2851 |
2852 |
2853 |
2854 |
2855 |
2856 |
2857 |
2858 |
2859 |
2860 | Action to be taken when filter matches.
2861 |
2862 |
2863 |
2864 |
2865 | String to compare the layout to.
2866 |
2867 |
2868 |
2869 |
2870 | Indicates whether to ignore case when comparing strings.
2871 |
2872 |
2873 |
2874 |
2875 | Layout to be used to filter log messages.
2876 |
2877 |
2878 |
2879 |
2880 |
2881 |
2882 |
2883 |
2884 |
2885 |
2886 |
2887 |
2888 |
2889 |
2890 |
2891 |
2892 | Action to be taken when filter matches.
2893 |
2894 |
2895 |
2896 |
2897 | Indicates whether to ignore case when comparing strings.
2898 |
2899 |
2900 |
2901 |
2902 | Layout to be used to filter log messages.
2903 |
2904 |
2905 |
2906 |
2907 | Substring to be matched.
2908 |
2909 |
2910 |
2911 |
2912 |
2913 |
2914 |
2915 |
2916 |
2917 |
2918 |
2919 |
2920 |
2921 |
2922 |
2923 |
2924 | Action to be taken when filter matches.
2925 |
2926 |
2927 |
2928 |
2929 | String to compare the layout to.
2930 |
2931 |
2932 |
2933 |
2934 | Indicates whether to ignore case when comparing strings.
2935 |
2936 |
2937 |
2938 |
2939 | Layout to be used to filter log messages.
2940 |
2941 |
2942 |
2943 |
2944 |
2945 |
2946 |
2947 |
2948 |
2949 |
2950 |
2951 |
2952 |
2953 |
2954 |
2955 |
2956 |
2957 |
2958 |
2959 |
2960 |
2961 |
2962 | Action to be taken when filter matches.
2963 |
2964 |
2965 |
2966 |
2967 | Layout to be used to filter log messages.
2968 |
2969 |
2970 |
2971 |
2972 | Default number of unique filter values to expect, will automatically increase if needed
2973 |
2974 |
2975 |
2976 |
2977 | Append FilterCount to the when an event is no longer filtered
2978 |
2979 |
2980 |
2981 |
2982 | Insert FilterCount value into when an event is no longer filtered
2983 |
2984 |
2985 |
2986 |
2987 | Max number of unique filter values to expect simultaneously
2988 |
2989 |
2990 |
2991 |
2992 | Max length of filter values, will truncate if above limit
2993 |
2994 |
2995 |
2996 |
2997 | Default buffer size for the internal buffers
2998 |
2999 |
3000 |
3001 |
3002 | Reuse internal buffers, and doesn't have to constantly allocate new buffers
3003 |
3004 |
3005 |
3006 |
3007 | How long before a filter expires, and logging is accepted again
3008 |
3009 |
3010 |
3011 |
3012 |
3013 |
3014 |
3015 |
3016 |
3017 |
3018 |
3019 |
3020 |
3021 |
3022 |
3023 |
3024 |
3025 |
3026 |
3027 |
3028 |
3029 |
3030 |
3031 |
3032 |
3033 |
3034 |
3035 |
3036 |
3037 |
3038 |
3039 |
3040 |
3041 |
--------------------------------------------------------------------------------
/src/PortProxy/PortProxy.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 | Exe
4 | netcoreapp2.0
5 |
6 |
7 |
8 |
9 |
10 | 1.4.3
11 |
12 |
13 | 2.0.0
14 |
15 |
16 | 4.5.0-beta07
17 |
18 |
19 | 1.0.0-rtm-rc2
20 |
21 |
22 |
23 |
24 | PreserveNewest
25 |
26 |
27 |
--------------------------------------------------------------------------------
/src/PortProxy/Program.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace PortProxy
4 | {
5 | using System.Collections.Generic;
6 | using System.Globalization;
7 | using System.Linq;
8 | using System.Reflection;
9 | using System.Threading;
10 |
11 | using Microsoft.Extensions.DependencyInjection;
12 | using Microsoft.Extensions.Logging;
13 |
14 | using NLog;
15 | using NLog.Extensions.Logging;
16 |
17 | class Program
18 | {
19 | static void Main(string[] args)
20 | {
21 | //# corefx bug of https://github.com/dotnet/corefx/issues/24832
22 | new ArgumentException();
23 |
24 | ConfigTraditionalLog();
25 | var serviceProvider = BuildDi();
26 | var logger = serviceProvider.GetRequiredService>();
27 |
28 | //log
29 |
30 | var local = args.Any(s => s == "--local");
31 | var port = GetOptionValue(args.FirstOrDefault(s => s.StartsWith("--port="))).ToInt32(local ? 1080 : 10240);
32 | var buffer = GetOptionValue(args.FirstOrDefault(s => s.StartsWith("--buffer="))).ToInt32(128) * 1024;
33 | var server = GetOptionValue(args.FirstOrDefault(s => s.StartsWith("--server="))).DefaultForEmpty(local ? "" : "127.0.0.1");
34 | var serverport = GetOptionValue(args.FirstOrDefault(s => s.StartsWith("--serverport="))).ToInt32(!local ? 1080 : 10240);
35 |
36 | if (local && server.IsNullOrEmpty())
37 | {
38 | logger.LogError("请指定一个远程服务器地址");
39 | return;
40 | }
41 |
42 | var srv = serviceProvider.GetRequiredService();
43 | srv.Init(buffer, port, local, server, serverport);
44 | srv.Start();
45 |
46 | while (true)
47 | {
48 | Thread.Sleep(100);
49 | }
50 | }
51 |
52 | static string GetOptionValue(string str)
53 | {
54 | if (string.IsNullOrEmpty(str))
55 | return null;
56 | return str.Substring(str.IndexOf('=') + 1);
57 | }
58 |
59 | static void ConfigTraditionalLog()
60 | {
61 | //workaround for log callsite bug (see https://github.com/NLog/NLog.Extensions.Logging/issues/165)
62 | LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging")));
63 | LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("Microsoft.Extensions.Logging.Abstractions")));
64 | LogManager.AddHiddenAssembly(Assembly.Load(new AssemblyName("NLog.Extensions.Logging")));
65 | }
66 |
67 | private static IServiceProvider BuildDi()
68 | {
69 | var services = new ServiceCollection();
70 |
71 | services.AddTransient();
72 | services.AddTransient();
73 | services.AddTransient();
74 |
75 | services.AddSingleton();
76 | services.AddSingleton(typeof(ILogger<>), typeof(Logger<>));
77 |
78 | var serviceProvider = services.BuildServiceProvider();
79 |
80 | var loggerFactory = serviceProvider.GetRequiredService();
81 | loggerFactory.AddNLog(new NLogProviderOptions {CaptureMessageTemplates = true, CaptureMessageProperties = true});
82 | loggerFactory.ConfigureNLog("nlog.config");
83 |
84 | return serviceProvider;
85 | }
86 | }
87 | }
88 |
--------------------------------------------------------------------------------
/src/PortProxy/Properties/PublishProfiles/FolderProfile.pubxml:
--------------------------------------------------------------------------------
1 |
2 |
6 |
7 |
8 | FileSystem
9 | Release
10 | netcoreapp2.0
11 | bin\Release\PublishOutput
12 |
13 |
--------------------------------------------------------------------------------
/src/PortProxy/Properties/launchSettings.json:
--------------------------------------------------------------------------------
1 | {
2 | "profiles": {
3 | "PortProxy": {
4 | "commandName": "Project",
5 | "commandLineArgs": "--local --server=192.168.94.4"
6 | }
7 | }
8 | }
--------------------------------------------------------------------------------
/src/PortProxy/Server.cs:
--------------------------------------------------------------------------------
1 | namespace PortProxy
2 | {
3 | using System;
4 | using System.Diagnostics;
5 | using System.Net;
6 | using System.Net.Sockets;
7 | using System.Runtime.InteropServices;
8 | using System.Threading.Tasks;
9 |
10 | using Microsoft.Extensions.DependencyInjection;
11 | using Microsoft.Extensions.Logging;
12 |
13 | using NLog;
14 |
15 | public class Server
16 | {
17 | private TcpListener _listener;
18 | private ILogger _logger;
19 | private int _bufferSize, _port;
20 | private bool _local;
21 | private IServiceProvider _serviceProvider;
22 |
23 | public string RemoteServer { get; private set; }
24 | public int RemoteServerPort { get; private set; }
25 |
26 | public Server(ILogger logger, IServiceProvider serviceProvider)
27 | {
28 | _logger = logger;
29 | _serviceProvider = serviceProvider;
30 |
31 | Debug.Assert(_serviceProvider != null, "No IServiceProvider found.");
32 | }
33 |
34 | public void Init(int bufferSize, int port, bool local, string remoteServer, int remoteServerPort)
35 | {
36 | _bufferSize = bufferSize;
37 | _port = port;
38 | _local = local;
39 | RemoteServer = remoteServer;
40 | RemoteServerPort = remoteServerPort;
41 | }
42 |
43 | ///
44 | /// 获得或设置是否是本地模式
45 | ///
46 | public bool Local => _local;
47 |
48 | public async void Start()
49 | {
50 | _logger.LogInformation("正在启动服务器端监听...");
51 | _listener = new TcpListener(IPAddress.Any, _port);
52 | _listener.Start();
53 | _logger.LogInformation($"服务器监听在端口 {_port}, 本地模式 {_local}...");
54 |
55 | var connectionCount = 0L;
56 | _logger.LogInformation("等待客户端连接...");
57 |
58 | while (true)
59 | {
60 | var client = await _listener.AcceptTcpClientAsync();
61 | connectionCount++;
62 |
63 | _logger.LogInformation($"#{connectionCount} 新的客户端连接 {client.Client.RemoteEndPoint} -> {client.Client.LocalEndPoint}");
64 |
65 | ProcessClientAsync(connectionCount, client);
66 | }
67 | }
68 |
69 | async void ProcessClientAsync(long connectionCount, TcpClient client)
70 | {
71 | IStreamTransformer CreateStreamTransformer(int key, int keyIndex)
72 | {
73 | var t = _serviceProvider.GetRequiredService();
74 | t.Init(key, keyIndex);
75 | return t;
76 | }
77 |
78 | var stream = client.GetStream();
79 |
80 | _logger.LogInformation($"#{connectionCount} 正在验证");
81 | var port = _local ? RemoteServerPort : _port;
82 | //验证
83 | var valid = false;
84 | var validator = _serviceProvider.GetRequiredService();
85 | if (!Local)
86 | {
87 | try
88 | {
89 | _logger.LogInformation($"#{connectionCount} 正在验证请求");
90 | valid = await validator.Validate(stream, port);
91 | }
92 | catch (Exception e)
93 | {
94 | _logger.LogInformation($"#{connectionCount} 验证错误:{e.Message}");
95 | }
96 | finally
97 | {
98 | _logger.LogInformation($"#{connectionCount} 验证结果:{valid}");
99 | if (!valid)
100 | {
101 | client.Close();
102 | }
103 | }
104 | }
105 | else
106 | {
107 | valid = true;
108 | }
109 |
110 | //parent
111 | var upclient = new TcpClient();
112 | NetworkStream upstream = null;
113 | if (valid)
114 | {
115 | try
116 | {
117 | _logger.LogInformation($"#{connectionCount} 正在连接上游服务器");
118 | await upclient.ConnectAsync(RemoteServer, RemoteServerPort);
119 | upstream = upclient.GetStream();
120 | _logger.LogInformation($"#{connectionCount} 上游服务器连接已打开 {upclient.Client.LocalEndPoint} -> {upclient.Client.RemoteEndPoint}");
121 | if (_local)
122 | {
123 | var buffer = validator.GenerateValiationData(port);
124 | await upstream.WriteAsync(buffer, 0, buffer.Length);
125 | }
126 | }
127 | catch (Exception e)
128 | {
129 | _logger.LogError($"#{connectionCount} 未能为打开上游服务器连接: {e.Message}");
130 | client.Close();
131 | valid = false;
132 | }
133 |
134 | if (valid)
135 | {
136 | await Task.WhenAny(
137 | ProcessStreamCopyAsync(stream, upstream, _local ? null : CreateStreamTransformer(port, 1), _local ? CreateStreamTransformer(port, 1) : null),
138 | ProcessStreamCopyAsync(upstream, stream, _local ? CreateStreamTransformer(port, 0) : null, _local ? null : CreateStreamTransformer(port, 0))
139 | );
140 | }
141 | }
142 |
143 | try
144 | {
145 | upstream?.Dispose();
146 | stream.Dispose();
147 | upclient.Client.Close();
148 | client.Client.Close();
149 | upclient.Close();
150 | client.Close();
151 | }
152 | catch (Exception e)
153 | {
154 | _logger.LogError($"#{connectionCount} 尝试关闭连接的时候发生错误 {e.Message}");
155 | }
156 |
157 | _logger.LogInformation($"#{connectionCount} 连接已关闭");
158 | }
159 |
160 | bool IsSocketConnected(Socket socket)
161 | {
162 | if (!socket.Connected)
163 | return false;
164 |
165 | return !(socket.Poll(0, SelectMode.SelectRead) && socket.Available == 0);
166 | }
167 |
168 | async Task ProcessStreamCopyAsync(NetworkStream srcStream, NetworkStream dstStream, IStreamTransformer readTransformer, IStreamTransformer writeTransformer)
169 | {
170 | var count = 0;
171 | var buffer = new byte[_bufferSize];
172 | do
173 | {
174 | try
175 | {
176 | count = await srcStream.ReadAsync(buffer, 0, buffer.Length);
177 | if (count == 0)
178 | continue;
179 |
180 | readTransformer?.Decode(buffer, 0, count);
181 | writeTransformer?.Encode(buffer, 0, count);
182 | await dstStream.WriteAsync(buffer, 0, count);
183 | }
184 | catch (Exception e)
185 | {
186 | break;
187 | }
188 | } while (count > 0);
189 | }
190 | }
191 | }
192 |
--------------------------------------------------------------------------------
/src/PortProxy/StreamTransformer.cs:
--------------------------------------------------------------------------------
1 | namespace PortProxy
2 | {
3 | using System;
4 | using System.Net;
5 |
6 | public class StreamTransformer : IStreamTransformer
7 | {
8 | public void Init(int keySource, int keyIndex)
9 | {
10 | throw new NotImplementedException();
11 | }
12 |
13 | public void Encode(byte[] buffer, int offset, int length)
14 | {
15 | throw new NotImplementedException();
16 | }
17 |
18 | public void Decode(byte[] buffer, int offset, int length)
19 | {
20 | throw new NotImplementedException();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/PortProxy/StreamValidator.cs:
--------------------------------------------------------------------------------
1 | namespace PortProxy
2 | {
3 | using System;
4 | using System.Net.Sockets;
5 | using System.Threading.Tasks;
6 |
7 | using NLog;
8 |
9 | class StreamValidator : IStreamValidator
10 | {
11 | public async Task Validate(NetworkStream stream, int key)
12 | {
13 | throw new NotImplementedException();
14 | }
15 |
16 | public byte[] GenerateValiationData(int key)
17 | {
18 | throw new NotImplementedException();
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------