zoukankan
html css js c++ java
[CSharp]向日志中写日志的代码,这样的代码能给打几分呢?
WriteAppEventLog.cs
/**/
/*
*******************************************************************
created: 2006/03/30
created: 30:3:2006 15:42
file ext: cs
author: xuzhong
purpose: 实现向应用程序日志中写日志
********************************************************************
*/
using
System;
namespace
XZSoftware.App.ZhengJun
{
public
class
WriteEventLog
{
public
WriteEventLog()
{
}
public
static
int
Main(
string
[] args)
{
int
argsLength
=
args.Length;
if
( argsLength
!=
4
)
{
Purging();
return
1
;
}
else
{
string
source
=
args[
0
];
string
message
=
args[
1
];
string
type
=
args[
2
];
string
id
=
args[
3
];
try
{
System.Diagnostics.EventLog.WriteEntry(
source , message , GetEventType(type) ,
int
.Parse(id) );
return
0
;
}
catch
{
return
-
1
;
}
}
}
public
static
System.Diagnostics.EventLogEntryType GetEventType(
string
type )
{
switch
( type.ToLower())
{
case
"
error
"
:
return
System.Diagnostics.EventLogEntryType.Error;
case
"
warning
"
:
return
System.Diagnostics.EventLogEntryType.Warning;
case
"
failureaudit
"
:
return
System.Diagnostics.EventLogEntryType.FailureAudit;
case
"
information
"
:
return
System.Diagnostics.EventLogEntryType.Information;
case
"
successaudit
"
:
return
System.Diagnostics.EventLogEntryType.SuccessAudit;
default
:
return
System.Diagnostics.EventLogEntryType.Error;
}
}
public
static
void
Purging()
{
Console.WriteLine(
""
);
Console.WriteLine(
""
);
Console.WriteLine(
"
********************************************************************
"
);
Console.WriteLine(
"
created: 2006/03/30
"
);
Console.WriteLine(
"
created: 30:3:2006 15:42
"
);
Console.WriteLine(
"
file ext: cs
"
);
Console.WriteLine(
"
author: xuzhong
"
);
Console.WriteLine(
"
"
);
Console.WriteLine(
"
purpose: 实现向应用程序日志中写日志
"
);
Console.WriteLine(
"
*********************************************************************
"
);
Console.WriteLine(
""
);
Console.WriteLine(
""
);
Console.WriteLine(
"
WriteAppEventLog.exe <source> <message> <type> <id>
"
);
Console.WriteLine(
"
source : 源
"
);
Console.WriteLine(
"
message : 内容信息
"
);
Console.WriteLine(
"
type : 日志类型 ( Error | Warning | Information | SuccessAudit | FailureAudit )
"
);
Console.WriteLine(
"
id : 标识错误的ID
"
);
Console.WriteLine(
""
);
Console.Write (
"
Sample :
"
);
Console.WriteLine(
"
WriteAppEventLog.exe \
"
My_Application\
"
\
"
This
is
a test.\
"
\
"
Error\
"
\
"
1000
\
""
);
}
}
}
build.bat
csc
/
t:exe
*
.cs
能打个几分呢?
查看全文
相关阅读:
mysql联合索引命中条件
Shiro知识初探(更新中)
Java中使用MongoTemplate进行分批处理数据
Java中String时间范围比较
使用ReentrantLock
使用Condition
python的坑--你知道吗?
python基础--函数全解析(1)
CSS基本语法及页面引用
HTML学习汇总
原文地址:https://www.cnblogs.com/xuzhong/p/362813.html
最新文章
Spring官网阅读 | 总结篇
Spring官网阅读(十八)Spring中的AOP
Spring官网阅读(十七)Spring中的数据校验
面试官:你说你懂动态代理,那你知道为什么JDK中的代理类都要继承Proxy吗?
面试官:你说你懂i++跟++i的区别,那你会做下面这道题吗?
HAProxy出现"远程主机强迫关闭了一个现有的连接 " 的错误及解决
nginx 502错误 upstream sent too big header while reading response header from upstream
asp.net 子应用程序/虚拟目录 session共享
IIS日志存入数据库之二:ETW
IIS日志存入数据库之一:ODBC
热门文章
在.net中使用ETW事件的方法
mssql借助链接服务器进行数据快速迁移
mssql中按周进行表分区的方法
DDD事件总线的实现
ReentrantReadWriteLock源码分析及理解
ReentrantReadWriteLock(读写锁)全部源码注释
读写锁doReleaseShared源码分析及唤醒后继节点的过程分析
ReentrantLock解析及源码分析
ThreadLocal原理分析
Spring AOP概念理解
Copyright © 2011-2022 走看看